How Can i update an html file using java code. suppose hi rancher is there in html file. I will search if rancher is there and replace that with some xyz text in the same file. How can i do that.
Hi just try File, BufferedInputStream and BufferedOutputStream. While reading the file just check for the string and if equals write the other string which is to be replaced.
You can either try using a RandomAccessFile or (using the methods Jeevi suggested) you can read the file in and write the entire contents plus the changes out to a temporary file and then delete the old file and rename the new one.
Note that RandomAccessFile will only work if the number of bytes you are replacing is exactly the same as the number of bytes you want to overwrite them with. If the numbers differ, the file will be garbage.