Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FileInputStream without Creating an Actual File using Java

Tags:

java

file-io

I was wondering if there was any way to create a FileInputStream object from just a file object without creating an actual file on the file system? What I am attempting to do is create a file object with some information, and then upload that file somewhere else. I have no need for it to be on the local file system. I know that I could just create a temp folder and then delete it afterwards, but was wondering if it was possible to not do it that way?

like image 395
Reid Mac Avatar asked Jan 10 '12 13:01

Reid Mac


2 Answers

What I am attempting to do is create a file object with some information, and then upload that file somewhere else

In that case you should not work with any file-related classes at all. Instead, crate a byte array, which you can tread as an InputStream via ByteArrayInputStream.

like image 174
Michael Borgwardt Avatar answered Sep 24 '22 09:09

Michael Borgwardt


You are probably looking for a ByteArrayInputStream or something similar.

A file input stream reads from a file on disk, that is its purpose. By the way, a File object in Java does not really represent a file, but rather the path pointing to a (potential) file on disk.

like image 39
Michael Piefel Avatar answered Sep 23 '22 09:09

Michael Piefel