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?
3 Answers
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.
4 Comments
Peter Lawrey
+1 You can use a ByteArrayOutputStream to help you build the data for the "file"
Reid Mac
I am having to call the following method which I cannot change, it's from the VersionOne API: createAttachment(String name, String fileName, InputStream stream) throws AttachmentLengthExceededException, ApplicationUnavailableException
Andrew Thompson
@ReidMac So what is the problems exactly?
Reid Mac
@AndrewThompson Nothing, just providing more information, sorry. Trying this now.
Try creating a memory stream, your file is stored in the memory instead of the file system
tmpfson Unix or a ramdisk on Windows. A ByteArrayInputStream is likely to be the simplest.