Two Laptop Bag
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Stream classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Stream classes" Watch "Stream classes" New topic
Author

Stream classes

Santosh Kumar Nayak
Ranch Hand

Joined: Aug 02, 2011
Posts: 141


Hello Folks,

am new to Java stream classess...

Why do we create instance of InputStreamReader and then instance of BufferedReader class while taking input from the Keyboard ?
Like Below:-

InputStreamReader isr=new InputStreamReader(System.in);

BufferedReader br=new BufferedReader(isr);

What is the purpose of the following above statements ?
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3991
    
  18

First, you create an InputStreamReader so you will be able to read characters from a stream of information. Streams are just series of bytes that you can interpret in any way you want. Readers interpret them as readable characters.

The BufferedReader is used to increase performance of the InputStreamReader. If you don't use a BufferedReader, you will only read a couple of bytes from the stream every time you read a portion of text. A BufferedReader however, will read much more bytes in one go, and store them in memory (also known as "data buffering").

Fewer big reads to file systems are much faster than lots of small reads. Using a BufferedReader makes sure that you don't have to worry about this.


The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
Santosh Kumar Nayak
Ranch Hand

Joined: Aug 02, 2011
Posts: 141
Thanks for the descriptive response.

anyways can you tell me:-

How to figure out as when to use Stream classes or use Reader classes for taking input from Input Devices ?
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3991
    
  18

If the input is all text, use a Reader. If not, use an InputStream.
Santosh Kumar Nayak
Ranch Hand

Joined: Aug 02, 2011
Posts: 141
If we want to save the methods of a class or Interface to a text file(say notepad) then how should we do it ?
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3991
    
  18

What do you mean by "saving methods"?
Santosh Kumar Nayak
Ranch Hand

Joined: Aug 02, 2011
Posts: 141
Sorry for bothering U.

I got it ...It is....

javap java.lang.String>my.text
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Stream classes
 
It's not a secret anymore!