1、PropertiesTest
- Properties:常用来处理配置文件,key和value都是
- Ctrl+shift+T:生成try/catch代码的快捷键
public class PropertiesTest {
//Properties:常用来处理配置文件,key和value都是String类型
//Ctrl+shift+T:选择一部分代码,生成部分代码的快捷键
public static void main(String[] args) {
FileInputStream fileInputStream = null;
try {
Properties properties = new Properties();
fileInputStream = new FileInputStream("jdbc.properties");
properties.load(fileInputStream);//加载流对应的文件
String name = properties.getProperty("name");
String password = properties.getProperty("password");
System.out.println("name="+name+",password="+password);
} catch (IOException e) {
e.printStackTrace();
} finally {
if(fileInputStream !=null) {
try {
fileInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
2、jdbc.properties
如果上边jdbc.properties文件中中文显示为unicode编码,则需要在idea中进行如下设置。