aspose file tools*
The moose likes Beginning Java and the fly likes Reading/Writing Formatted Text Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Reading/Writing Formatted Text" Watch "Reading/Writing Formatted Text" New topic
Author

Reading/Writing Formatted Text

Steven Smith
Greenhorn

Joined: Dec 12, 2005
Posts: 14
I'm trying to read a file with formatted text (tabbing etc.), then writing it to a new file. However, the formatting is getting lost to the new file. What should I do?
What I tried:
FileWriter out = new FileWriter(outfile);
BufferedReader br = new BufferedReader(new FileReader(infile));
String tmpstr = "";
while((tmpstr = br.readLine()) != null) {
out.write(tmpstr);
}
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
You shoud write the tabs

Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
You're using readln() which "eats" the newline off the end of each line. Try writing the newLine() method after writing each line. Also see how you like PrintWriter which has println().


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Steven Smith
Greenhorn

Joined: Dec 12, 2005
Posts: 14
Thank you all for your help! Just wondering though if there are any methods that will automatically read/write the '\r', '\n', '\t', etc. The problem is, I can't visibly see these in the input file. I only know they are there because the output file formatting is all "out of whack".
[ September 28, 2006: Message edited by: Steven Smith ]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
If you read lines you're pretty much asking to remove newlines. You can pass everything from input to output if you use bytes and streams instead of Strings and reader & writer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading/Writing Formatted Text
 
Similar Threads
another File reading problem
unwanted chars
Remove Line from Text File
Writing data into file from a String variable
Is PrintWriter Buffered?