我正在尝试为属性添加键值,它不会保存。
请帮助我!
Properties message_properties=new Properties();
InputStream is = this.getClass().getResourceAsStream("/resource/messages.properties");
message_properties.load(is);
message_properties.setProperty("key1", "value1");
message_properties.store(outputStream,null);
答案 0 :(得分:1)
您必须使用inputStream来读取属性文件,并使用outputStream来写入文件。
Properties prop = new Properties();
//read using input stream
InputStream in = getClass().getResourceAsStream("file location");
prop.load(in);
in.close();
//set property
prop.setProperty("key","value");
//store using output stream
prop.store(new FileOutputtream("File_Location");