1.不在项目中读取
Properties properties = new Properties();
BufferedReader read = new BufferedReader(new InputStreamReader(new FileInputStream("文件的路径"),"utf-8"));
properties.load(read);
properties .getProperty("那个文件的key")
BufferedReader read = new BufferedReader(new InputStreamReader(new FileInputStream("文件的路径"),"utf-8"));
properties.load(read);
properties .getProperty("那个文件的key")
2.在项目中读取
InputStream inputStream =你那工具类的类名.class.getResourceAsStream("/文件名.properties");
Properties p = new Properties();
try {
p.load(inputStream);
inputStream.close();
} catch (IOException e1) {
e1.printStackTrace();
}
Properties p = new Properties();
try {
p.load(inputStream);
inputStream.close();
} catch (IOException e1) {
e1.printStackTrace();
}
都是通过p.getProperty(配置文件里的key)获得value的