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?
Printable View
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?
read the file into a string (fully or buffered) use the String.replace method then write the string back to the 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.