java 读写.properties

读取properties 文件

    Properties prop == new Properties();
    prop.load(getClass().getClassLoader().getResourceAsStream("version.properties"));
    String latest = prop.getProperty("latest_version");
    String location = prop.getProperty("location");

写/修改 properties 文件内容

      FileOutputStream outputFile = new FileOutputStream(req.getRealPath("/")+"WEB-INF/classes/version.properties");//获取文件所在路径
    prop.setProperty("latest_version", latest);
    prop.setProperty("location", location);
     try {
     prop.store(outputFile, "UTF-8");
   } catch (IOException e) {
     // TODO Auto-generated catch block
    e.printStackTrace();
   try {
    outputFile.close();// 关闭流
    } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
}
} catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }

你可能感兴趣的:(java)