|
-
Aug 26th, 2008, 06:14 AM
#1
Thread Starter
Frenzied Member
changing some words in a text file
i have some textfiles with essay in them. i want to change all the words 'dogs' to 'cats' automatically by code
anyone know how i could do this in java?
-
Aug 26th, 2008, 07:01 AM
#2
Re: changing some words in a text file
read the file into a string (fully or buffered) use the String.replace method then write the string back to the file
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Aug 29th, 2008, 05:34 AM
#3
Re: changing some words in a text file
Hi,
Just like what ComputerJy said, read the file using BufferedInputStream for buffered.
The way I would work with it is, read the file line per line. For each line replace the text to replace and then write it out to a temp file. When all lines are read and written, delete the original file and rename the temp into the original file.
lots of approach really. not sure if mine is the fastest you'll have to do a bit more research.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|