我正在尝试修改此ini文件的dbVersion属性值
[Settings]
Access=ReadWrite
Type=1
AutomationDbString=jdbc:mysql:ser=php&password=php
automationServerTestResultPath=/testresult/
automationServerTestResultPathWrite=testresult
automationServerTestResultPathRead=http:testresult
automationServerBuildPath=\testresult\\builds
automationServerReferenceFilesPath=\\reference_files
automationToolBaseUrl=http:/dpa
agentInstallBuildFolder = c:\\dev\\builds
agentAntLogFolder = c:\\dev\\logs
exportToTaf=true
dbEnable=true
dbVersion=606A8
dbName=archauto606
archticsLocation=//source/QA
userName=Administator
pwdName=hombre007!
archticsPatchLocation=patch\
[Root]
执行这部分代码后,我的文件结构发生了变化
Properties p = new Properties();
p.load(new FileInputStream("C:\\agent\\Testcomplete2.ini"));
System.out.println("dbVersion = " + p.getProperty("dbVersion"));
p.setProperty("dbVersion", "606A21");
p.store(new FileOutputStream("C:\\agent\\Testcomplete2.ini"), null);
#Mon Jul 22 13:49:54 EDT 2013
[Root]=
agentInstallBuildFolder=c\:\\dev\\builds
AutomationDbString=jdbc\:mysql\:ser\=php&password\=php
automationServerBuildPath=\testresult\\builds
automationServerTestResultPathWrite=testresult
dbVersion=606A21
pwdName=hombre007\!
exportToTaf=true
Type=1
userName=Administator
automationServerTestResultPathRead=http\:testresult
dbEnable=true
archticsPatchLocation=patch
[Settings]=
automationServerReferenceFilesPath=\\reference_files
Access=ReadWrite
automationToolBaseUrl=http\:/dpa
archticsLocation=//source/QA
automationServerTestResultPath=/testresult/
dbName=archauto606
agentAntLogFolder=c\:\\dev\\logs
然而,在执行p.store行之后,我注意到我的文件结构已经改变,我无法解析推进文件。只是询问是否有办法只修改值而不改变文件的结构。
感谢您的帮助。
答案 0 :(得分:0)
似乎Properties.load()
和Properties.store()
不一定保证条目(甚至部分)的存储顺序 - 可能是因为内部使用的数据结构存储{{1的结果可能是哈希表或类似的东西。如果是这种情况,并且您的解析因此而中断,则您必须a)修复您的解析代码以不依赖于特定顺序的事物或b)编写您自己的代码来进行替换而不是依赖于load()
/ load()
方法......