我正在尝试向属性添加键值,但它不起作用。请帮帮我

I'm trying to add key,value to properties, it does not work. help me, please

我正在尝试将键值添加到属性中,但它没有保存。

请帮帮我!

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);

您必须使用 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");