1

我正在尝试修改此 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 行之后,我注意到我的文件结构发生了变化,我无法解析该文件。只是询问是否有办法只修改值而不改变文件的结构。

感谢您的帮助。

4

1 回答 1

0

看起来Properties.load()并且Properties.store()不一定保证条目(甚至部分)的存储顺序 - 可能是因为内部用于存储结果的数据结构load()可能是哈希表或类似的东西。如果是这种情况,并且您的解析因此中断,您将不得不a)修复您的解析代码以不依赖于特定顺序的事物或b)编写您自己的代码来进行替换不要依赖load()/store()方法...

于 2013-07-22T18:13:30.260 回答