7

I have stream saved in ByteArrayOutputStream. now I want to to read that in FileInputStream. how Can I do that?

it's my outputStream.

...
OutputStream out = new ByteArrayOutputStream();
...

now how to read that, from FileInputStream?

Uwe Plonus
  • 9,803
  • 4
  • 41
  • 48

1 Answers1

16

You can create a ByteArrayInputStream with

InputStream is = new ByteArrayInputStream(bos.toByteArray());

and then read from this InputStream.

If your interface only accepts a FileInputStream then the interface is broken...

If, at all, an interface only works with files it should accept a File else it should use an InputStream.

Also if you use threads you can use PipedInputStream and PipedOutputStream directly between the threads.

Uwe Plonus
  • 9,803
  • 4
  • 41
  • 48
  • I need only FileInputStream. or I have byte array (byte [] variable) and I want to read from FileInputStream –  Jul 11 '13 at 14:32
  • 2
    +1 for "If your interface only accepts a `FileInputStream` then the interface is broken" – Ian Roberts Jul 11 '13 at 14:47