I have requirement to copy content from one file to another. So is my below code. But the additional requirement is that the second character in every line should be checked and changed to character 'X'. Please let me know how can this be checked.
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.
I yam what I yam and that's all that I yam - the great philosopher Popeye. Tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss