Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java BufferedReader and BufferedWriter

 
harrell collins
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am writing a program that uses BufferedReader to Read through a postscript file and number the lines. So that I can write a postscript instruction at specific line numbers. However, I am encountering an error when I try to use BufferedWriter. I have tried closing the BufferedReader to no avail. Can anyone share insight of code that will help with this. Also can anyone recommend a way to search through a directory for files using a wildcard e.g "/e3/MAILING/1028.*". any insight or help would be appreciated.
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this code snippet I take a source file and while I read it with a LineNumberReader, when I process a particular line, I do something special with the text (in this case I reverse it). While I read the file, I copy it to a temporary file. At the end I replace the original file with the new temporary file.

Another approach is to use a memory stream to store temporary information, before writing back to file.



Regars,
Edwin Dalorzo.
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As for the listing files in a directory you can use the java.io.FileFilter or the java.io.FilenameFilter.

Look at this code snippet.



Regards,
Edwin Dalorzo.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic