0
我有一个属性文件这样的文件:如何妥善保存性能有特殊字符
[flags]
prop1=value
prop2=value
[patterns]
prop3=#.00
prop4=###,##0.00
[other]
prop5=value
当我处理文件,不仅磅符号被转义(#),但我的所有属性都没有秩序。
我的代码是这样的:
Properties props = new Properties();
FileInputStream in = null;
try
{
in = new FileInputStream(PROP_FILE);
Reader reader = new InputStreamReader(in, StandardCharsets.UTF_8);
props.load(reader);
}
catch (IOException e)
{
// log exception
}
finally
{
if (in != null)
{
try
{
in.close();
}
catch (IOException e)
{
// log exception
}
}
}
props.setProperty("prop5", "otherValue");
try
{
OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(INI_FILE), StandardCharsets.UTF_8);
props.store(w, null);
}
catch (IOException e)
{
// log exception
}
我使用props.store()
,因为我不知道的另一种方式,以节省props.setProperty()
被调用后属性文件。
这听起来像你试图使用不正确的属性文件。他们不是*要求下令,是的,当他们需要的时候,事情就会逃脱。这听起来像你真的想要像Windows的“ini”文件... –
@JonSkeet,谢谢!就是这样。多年前,我用ini4j来做到这一点。我会仔细看看的。再次,谢谢! – hfontanez