JAVA中properties资源调用简单示例

来源:互联网 发布:狗哥王兆辉 知乎 编辑:程序博客网 时间:2024/06/07 23:39
import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.InputStream;import java.util.Properties;class PropertiesTest {public static void main(String args[]){Properties properties = new Properties();String projectPath = System.getProperty("user.dir");String propertiesPath = projectPath + File.separator + "resources" + File.separator + "first.properties";try {InputStream in = new FileInputStream(propertiesPath);//不要忘记导入propertiesproperties.load(in);System.out.println(properties.getProperty("key1"));} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}}

资源文件为 resources文件夹下的first.properties.内容:

key1 = properties test

输出结果: properties test

0 0
原创粉丝点击