0

Is it possible to get an InputStream out of an InputStreamReader instance? If yes, how?

EDIT: i'm reading a binary file over network, so i need to read bytes, not chars. I haven't found a way to do this with an InputStreamReader....

user2422196
  • 297
  • 3
  • 13

1 Answers1

3

Not without reflection, no... and I really wouldn't recommend using reflection here. (You would be very implementation-specific.)

Usually you shouldn't care about which implementation of Reader is being used at all, so you wouldn't even know it was an InputStreamReader... let alone try to get access to the underlying InputStream.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • the problem is that i want to read Bytes, not Chars. changing everything to an InputStream would be much work, so i hoped i can get one out of the reader – user2422196 Mar 05 '14 at 18:51
  • 1
    @user2422196: If you want to read binary data, you shouldn't have a `Reader to start with, almost certainly. Again, without any context about where this reader is coming from etc it's hard to help you, but it sounds like a situation you should just try to avoid. – Jon Skeet Mar 05 '14 at 18:53