java读取配置文件(使用java.util.Properties读取)
2017-11-03 14:14
716 查看
读取resource下的test.properties文件,代码如下
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class PropertiesUtil {
public String getValue(String name){
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("test.properties");
Properties properties = new Properties();
try{
properties.load(inputStream);
}catch (IOException ioE){
ioE.printStackTrace();
}finally{
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println(name+":"+properties.getProperty(name));
return properties.getProperty(name);
}
}
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class PropertiesUtil {
public String getValue(String name){
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("test.properties");
Properties properties = new Properties();
try{
properties.load(inputStream);
}catch (IOException ioE){
ioE.printStackTrace();
}finally{
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println(name+":"+properties.getProperty(name));
return properties.getProperty(name);
}
}
相关文章推荐
- 使用java.util.Properties读取配置文件信息
- 使用java.util.Properties读取文件
- JAVA读取classess下的.properties配置文件封装类,linux和windows上都可以使用
- 使用java读取配置文件(ini、properties)
- java 通过 Properties 读取数据库配置 .properties 文件的使用。
- java.util.ResourceBundle 和java.util.properties 读取配置文件区别
- Eclipse和Tomcat和Java读取配置文件工具类PropertiesUtil
- java使用java.util.Properties读取properties文件的九种方法
- Java使用properties读取配置文件
- 读取资源属性文件(properties)java.util.ResourceBundle使用详解
- java IO 使用Properties设置键值对配置信息 写入文件和从文件中读取
- 【Properties文件】Java使用Properties来读取配置文件
- java.util.ResourceBundle 和java.util.properties 读取配置文件区别
- java.util.Properties读取中文内容的配置文件,发生中文乱码的现象有解决方案
- Java Properties 类读取配置文件信息
- java 读取properties配置文件
- 用Properties读取配置文件后,使用TreeMap对keys进行排序
- java.util.Properties 读取资源文件
- java 读取 properties 配置文件 备忘
- Java Properties 类读取配置文件信息