• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java BufferedReader and BufferedWriter

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
To get a wish, you need a genie. To get a genie, you need a lamp. To get a lamp, you need a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic