0

I have a Class, that expects an InputStream on input. Currently I am loading a text file from filesystem and creating FileInputStream, that is passed to this Class.

What I need is to eliminate the need of file in filesystem to be able to create an InputStream.

So I came up with solutions like:

  • Storing a file into String variable and creating Stream out of it (escaping chars need to be done)
  • Storing a file into byte array with hex values (no need to escape chars or care about content)

I am wondering if there is any other way to achieve this.

arenaq
  • 2,304
  • 2
  • 24
  • 31
  • I dont get it... you want to read the content and remove the file from the filesystem? – Zelldon Jul 30 '15 at 07:07
  • Are you looking for ByteArrayInput/OutputStream? But this does not replace a File object if you want to read a real file from a file system. – Konrad Jul 30 '15 at 07:14
  • Already answered here: http://stackoverflow.com/questions/247161/how-do-i-turn-a-string-into-a-stream-in-java?rq=1 – shae Jul 30 '15 at 07:51
  • I studied your link and I do not believe the "answers" in there is sufficient to answer my question... I already said I know how to do it with String and ByteArray, they are talking only about these two solutions, I asked if there is another way... – arenaq Jul 30 '15 at 08:03
  • If you have a file, and you need an `InputStream`, the `FileInputStream` class meets your need perfectly. What exactly is the problem you're trying to solve? – user207421 Jul 30 '15 at 09:46
  • "What I need is to eliminate the need of file in filesystem to be able to create an InputStream." Simply because I want to hide this file to be not seen or edited. – arenaq Jul 30 '15 at 10:37

0 Answers0