File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes writing data into a file only some part Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "writing data into a file only some part" Watch "writing data into a file only some part" New topic
Author

writing data into a file only some part

Chennarao Marvatu
Ranch Hand

Joined: Aug 09, 2004
Posts: 32
Hello Friends ,
I have to modify my client property file every time
i.e. i need to overwrite some part of my property file
how can do that i have dome like this but not working
Here i have to modify NotificationServer part only when i login into the
system.pls help me out

HashMap versionUpdates=secReqObject.getVersionInfo();
//here versionUpdate is the Server peroperty Object

String notificationServ = (String)versionUpdates.get("NotificationServerName");
String notificationUser = (String)versionUpdates.get("NotificationServerUName");
String notificationPass = (String)versionUpdates.get("NotificationServerPwd");

StringBuffer sb1 = new StringBuffer();
sb1.append("###NOTIFICATION SERVER");
sb1.append("\r\n");
sb1.append("NotificationServerName=");sb1.append(notificationServ);
sb1.append("\r\n");
sb1.append("NotificationServerUName=");sb1.append(notificationUser);
sb1.append("\r\n");
sb1.append("NotificationServerPwd=");sb1.append(notificationPass);
sb1.append("\r\n");
System.out.println("PROPERTIES FROM SERVER"+sb1);
FileWriter f = new FileWriter(iniFilePath,true);
f.write(sb.toString());
f.close();


Thanks
Chennarao


mchrao
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12809
    
    5
There is nothing to be gained by trying to modifiy your properties file this way. Just use the methods in the java.util.Properties class to set the new values and write the whole thing back out to the file. Much simpler.
Bill
Shekar Atmakur
Ranch Hand

Joined: Oct 24, 2003
Posts: 36
If you use ANT to do your builds, and if that file needs to change at compile time then ANt can do the job for you pretty efficiently
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: writing data into a file only some part