• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stream classes

 
Santosh Kumar Nayak
Ranch Hand
Posts: 143
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Pie
Posts: 5893
63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 143
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 5893
63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the input is all text, use a Reader. If not, use an InputStream.
 
Santosh Kumar Nayak
Ranch Hand
Posts: 143
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 5893
63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "saving methods"?
 
Santosh Kumar Nayak
Ranch Hand
Posts: 143
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for bothering U.

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

javap java.lang.String>my.text
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic