Java属性:如何保留非key = value行? [英] Java Properties: How to keep non key=value lines?

查看:85
本文介绍了Java属性:如何保留非key = value行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用属性修改Java中的配置文件。

I am trying to modify a config file in Java using Properties.

我使用Properties.store,load和setProperty成功地读取,写入和修改了行,但是我注意到在执行了此类操作之后,文件被覆盖了,因此我失去了所有配置文件中不是键值对的行。即,我松开了注释。

I read, write and modify the lines successfully using Properties.store, load and setProperty, but I noticed that after doing such operation the file is overwritten and thus I loose al the lines in the config file that are not key-value pairs. Namely, I loose the comments.

是否有一种方法可以使用java.util保留此类行?

在每行中放置前缀不是问题。我知道如何逐行逐行阅读;我要的是替代方案

Placing a prefix in each line is not a problem. I know how to do it 'manually' reading line by line; I'am asking instead for an alternative

推荐答案

我认为这不可能。请注意,属性也不保证从load()到store()或从一个store()到另一个store()的顺序是相同的。如果可能,属性的javadoc会告诉您如何操作。

I don't think it is possible. Note that properties also don't promise that the ordering will be the same from load() to store(), or from one store() to another. If it is possible, the javadoc for Properties will tell you how.

这篇关于Java属性:如何保留非key = value行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆