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....

5
  • 1
    My answer is basically a long-winded "no" - but if you can give more context we may be able to give more guidance. Commented Mar 5, 2014 at 18:47
  • If you are sending a file, why should you want to read it? Commented Mar 5, 2014 at 18:56
  • sry, i want to read a binary file ;) Commented Mar 5, 2014 at 19:06
  • Well read it with an InputStream, why not? Commented Mar 5, 2014 at 19:10
  • i had to make some major changes in my sourcecode to get an InputStream. luckily, they were not so big as i thought they would be. :) Commented Mar 5, 2014 at 19:15

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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: 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.