Eshwar Prasad wrote:
That's going to give you problems. read moves the file's internal pointer forward, so some data will be read but never used.
You mention lines. Then you shouldn't read byte[] per byte[]. Instead, switch to something that knows how to read lines; a BufferedReader around a FileReader perhaps. (Don't forget to switch from FileOutputStream to FileWriter as well.)
Then read the file line by line, modify the line (warning: what if the line has 0 or 1 characters?) and write it to the file (using FileWriter). Don't forget to add new line breaks yourself, because most (all?) line reading classes strip away the line breaks.