• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading/Writing Formatted Text

 
Steven Smith
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shoud write the tabs

 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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().
 
Steven Smith
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic