aspose file tools
The moose likes Beginning Java and the fly likes Update the character on file writing. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Update the character on file writing." Watch "Update the character on file writing." New topic
Author

Update the character on file writing.

Eshwar Prasad
Ranch Hand

Joined: Mar 21, 2008
Posts: 191
Hello

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.


Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Update the character on file writing.
 
Similar Threads
File read write problem
How to correctly use this read() write()
JCE Code
how to zip multiple files and directory into one output
how to copy a file from one folder to another folder?