2013-07-22 45 views
1

我想修改dbVersion属性的值,这个ini文件更新INI文件 - 问题与存储功能

[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

这似乎是Properties.load()Properties.store()并不一定能保证在条目(甚至部分)存储顺序 - 可能是因为内部使用,用于存储load()结果的数据结构可能是一个哈希表或类似的东西。如果是这种情况,并且解析因此而中断,则必须或者a)修复解析代码,使其不依赖于特定顺序的事物;或者b)编写自己的代码来执行替换, t依靠load()/store()方法...

+0

我发现了一个名为InitEditor的eclipse库,并解决了我的问题。谢谢 。 –