This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes modify a string in file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "modify a string in file" Watch "modify a string in file" New topic
Author

modify a string in file

Smitha Vallaru
Greenhorn

Joined: Aug 15, 2006
Posts: 16
Can anyone let me now how to modify a string in a partiuclar file. i have used file reades to read each line(to buffer) and stored in string and checked for particular line but unable to modify it.

Thanks
Smitha.
Jaime M. Tovar
Ranch Hand

Joined: Mar 28, 2005
Posts: 133
I think there is no direct way to do it. You have to create a new file. There you can write the data as you are reading from the original file, when you find the string you are looking for just write your String and continue with the rest of the file.


She will remember your heart when men are fairy tales in books written by rabbits.<br /> As long as there is duct tape... there is also hope.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41141
    
  45
The RandomAccessFile class can do this, although possibly only if the old string and the new string have the same length.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: modify a string in file
 
Similar Threads
writeUTF() and writeBytes()
string to be replaced in a file
Update a file when a token occurs
Need help Read the File and replace its Header contents
Help - Please explain