有没有办法只用Java覆盖属性文件中的一个字段?覆盖属性文件
例如,如果我的app.properties看起来像
dbpassword=password
database=localhost
dbuser=user1
,我想它只有一个的setProperty命令,即改为
dbpassword=password
database=localhost
dbuser=user2
,而无需重写我的其他领域,可我这么做?我尝试了以下方法:
prop.setProperty("dbuser", "user2");
prop.store(new FileOutputStream("app.properties",true), null);
但它只是将该属性附加到该文件并且不覆盖现有的dbuser字段。
那么,如果你只是想再次从属性文件中读取...这最终将工作;如在附加文件中将使用最后一个值。话虽如此,我相信这不是你想要达到的。你想保护数据吗? – SiB 2012-07-31 04:27:23