java: performing modification in file.
Hi,
I have a file like file1.txt. It contain more than 1000 lines. My requirement is to perform the modification in 15th line of file1.txt.
But i know the code like to read the all lines form file1.txt and performing the modification in 15 th line and store the modification content in another file like fil2.txt. My requirement is just perform the modification only one word in 15th line, but the above logic take so much time to read and write the content .
Please share is there any another bettor logic to change the content in file ?
Re: java: performing modification in file.
Normally with a text file, to modify part of it, all of it must be read and written, unless the modification fits exactly over the existing data then the modification could be done by writing over the bytes to be modified.
For example if the mod was to change three bytes at location 250, then the bytes at 250, 251 and 252 could be written to with the new data. The RandomAccessFile could be used for that.
Re: java: performing modification in file.