Properties
文章目录
Tips
- 常用来处理配置文件。key和value都是String类型
- 如果中文出现乱码的话,注意检查idea设置,设置之后要重新创建文件
示例
name=Tom
password=abc123
public static void main(String[] args) {
FileInputStream fis = null;
try {
Properties pros = new Properties();
fis = new FileInputStream("jdbc.properties");
pros.load(fis);
String name = pros.getProperty("name");
String password = pros.getProperty("password");
System.out.println("name = " + name + ", password = " + password);
} catch (IOException e) {
e.printStackTrace();
} finally {
if(fis != null){
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
|