我是靠谱客的博主 魁梧服饰,这篇文章主要介绍java将常量设置在配置文件中,读取配置文件,现在分享给大家,希望可以做个参考。

将常量设置在配置文件中,读取配置文件

package properties;

import org.testng.annotations.Test;
import java.io.FileInputStream;
import java.util.Properties;
public class Constant {
    public static Properties prop = getProperties();
    public static Properties getProperties() {
        Properties prop = new Properties();
        try {
            FileInputStream file = new FileInputStream("src/main/resources/test.properties");
            prop.load(file);
            file.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return prop;
    }

    @Test
    public void test(){
        Constant  ctest=new Constant();
        Properties prop = ctest.prop;
        System.out.println(prop.getProperty("test.name"));
    }
}

 

 

test.properties文件中内容为:

test.name = javascript

最后

以上就是魁梧服饰最近收集整理的关于java将常量设置在配置文件中,读取配置文件的全部内容,更多相关java将常量设置在配置文件中内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(170)

评论列表共有 0 条评论

立即
投稿
返回
顶部