• Post Reply Bookmark Topic Watch Topic
  • New Topic

Difference between InputStream and InputStreamReader  RSS feed

 
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there..

I read that InputStream is used for byte based reading it reads 1 byte at a time.
And InputStreamReader is used for charcter based reading so it reads one charcter at a time so no need to convert this first to int then read it.

Here is reading using InputStream.


and here is reading using InputStreamReader




so what is difference between InputStream and InputStreamReader in both case i have to use a Int and then read it and at the end if I want to print that data I have to cast that with "(char)c".

So what is advantage of using InputStreamReader?


Thanks
 
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the docs:

An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified charset.


IRL you probably want:

 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sure I have sent you to the Java Tutorials before, but you should find answers to all your questions in there.

If you are starting, start by learning NIO2 rather than the older input classes.
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Campbell
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!