【发布时间】:2018-02-18 15:40:58
【问题描述】:
我有一个属性文件(ab.properties),其值如下:
颜色=橙色
storeLocation=./test.json
公司=苹果
我想将storeLocation的值修改为C:\Users\kumar\testFiles\test.json
在代码中,file 是我读取 ab.properties 文件的路径,storelocation1 包含路径 C:\Users\kumar\testFiles\test.json(我想在 storelocation 中更新)。见以下代码:
try (InputStream in = new FileInputStream(file)) {
Properties prop = new Properties();
prop.load(in);
in.close();
prop.setProperty("storeLocation", storeLocation1);
OutputStream out = new FileOutputStream(file);
prop.store(out, null);
out.close();
}catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
通过使用上面的代码,我得到以下输出:
颜色=橙色
storeLocation=C\:\\Users\\kumar\\testFiles\\test.json
公司=苹果
storeLocation 的值正在更新,但是
我想要 C: 而不是 C\: 。有人可以指导我吗?
【问题讨论】:
-
"我想要 C: 而不是 C:" ?这是什么意思?
-
哎呀,当我发布此查询时,似乎没有正确使用反斜杠字符。我得到的输出为
-
storeLocation=C\:\\Users\\kumar\\testFiles\\test.json
-
所以我想要 C: 而不是 C\:
标签: java properties fileinputstream fileoutputstream properties-file