File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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: 95


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: 3647
    
  16

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.
Santosh Kumar Nayak
Ranch Hand

Joined: Aug 02, 2011
Posts: 95
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: 3647
    
  16

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

Joined: Aug 02, 2011
Posts: 95
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: 3647
    
  16

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

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

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

javap java.lang.String>my.text
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Stream classes