• Post Reply Bookmark Topic Watch Topic
  • New Topic

overwriting some part of file(UPDATING ONLY SOME PART)  RSS feed

 
Chennarao Marvatu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Friends ,I have been trying but i am not getting this.
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


[MedPlexus]

AppPath=C:\MedPlexus
InstallationType = SA/IN
PracticeCode=1234
LastLoginTimeStamp=10/20/2004-12:40:30
InstallationTimeStamp=10/21/2004-9:40:30


[POMS]

Version = v1
Release = 6.23
DeploymentType = ( ASP/LD)

LatestClientVersion = v1
LatestClientRelease = 6.23

LatestServerVersion = v2
LatestServerRelease = R4.6.27

LatestDownloadedversion=v1
LatestDownloadedRelease=R4.6.23


ServerName=192.168.1.100

ASPFTPServerName =192.168.1.100
ASPFTPUserName=indus-eoffice/rambabu
ASPFTPPwd=rambabu

NotificationServerName=dsateesh
NotificationServerUName=INDUS
NotificationServerPwd=INDUS


[UPDATES_INSTALLER]

CurrentVersion =
CurrentRelease =

Latest Version =
LatestRelease=


NetworkShareFolder =


LocalFTPServerName=
LocalFTPUserName=
LocalFTPPassword=


[INSTALLATION_SERVICE]

CurrentVersion =
CurrentRelease =

Latest Version =
LatestRelease=


MachineName=
PortNumber=

This is my client property file ..i need to update every time when i login
only NotificationServer Part...
NotificationServerName=dsateesh
NotificationServerUName=INDUS
NotificationServerPwd=INDUS



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
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The java documentation for FileWriter has the following to say about the constructor that takes a String and a boolean:

public FileWriter(File file, boolean append) throws IOException

Constructs a FileWriter object given a File object. If the second argument is true, then bytes will be written to the end of the file rather than the beginning.


You don't want to write data at the end of the file, right? You have two choices, each has it's plusses and minuses:
1. read the file in, change the data in memory, and write it back out again. You'll have to rename or delete the existing file depending on how you want to deal with exceptions or unforseen problems.
2. use java.io.RandomAccessFile. RandomAccessFile views a file as an array of data. You can write to a point in the "array" and it changes the data in the file. Of course, if you try to write more data than there is space for, you can change data you don't intend to.
The Java Tutorial chapter on IO is a good source for more information.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!