Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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 ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

IO classes, I hate them..

Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,
i am working in Java since last 2 yrs,
I never worked much on IO classes.
Never required,
whenever i want to use i just go through docs and find out suitable class.

But when it comes to SCJP, i found questions asking, which class provides line reading methods.???

It is so hard to remember so many classes, PrintWriter, BufferedReader, FileReader etc etc.
Actually here, Decorator pattern makes it hard.

Is there any good IO tutorial?? which helps me to remember.
Or guys help me out, how you did it.

Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suggest that you read the K&B chapter on IO and try some code on the different methods. Once you are comfortable with this then move on to mock questions.

A good tutorial on IO can be found here:
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Go very slowly on IO part. Do not try learn in one shot....
Make examples.. you will find very easy...

For reader part:
1) FileReader is lowerlevel reader, it can read a single char or a char[]. It depends on the InputStreamReader for its api. See these class in java source code, you will find it helpful.
2) After FileReader next comes BufferedReader. It only takes reader in constructor. The benefit over FileReader is that it has buffer to store read characters, so it can read a line. That's why it has readLint() method that reads whole characters in a line into a buffer then returns a String containg charaters of a line.

For writer part: it is like reader part but it has an extra class PrintWriter.

1) Just like FileReader, it is lower lever writer, it depends on OutputStreamWriter for its APIs. It can write a single char, char[] and String. And It can flush, as it is writer. No flush required in reading part.

2) Wrapper of FileWriter is BufferedWriter, it takes writer in the constructor. Only benefit over FileWriter is that it has newLine() method that writes a line separator.

3) PrintWriter, it has benefit that it can take writer, file, String filename and OutputStream in the constructor. But it has lots of method. like append(), write(), print(), printf(), println(), format(), checkError(), format() with Locale.

If you complete this much course, then you can handle all the questions easily.
    Bookmark Topic Watch Topic
  • New Topic