Properties处理属性文件
package com.at.test;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
/**
* @author JessieWu
* @create 2020-08-11 16:56
*/
public class PropertiesTest {
public static void main(String[] args) throws Exception {
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){
fileInputStream.close();
}
}
}
}
网友评论