7

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?

1
  • You could use tmpfs on Unix or a ramdisk on Windows. A ByteArrayInputStream is likely to be the simplest. Commented Jan 10, 2012 at 13:36

3 Answers 3

5

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.

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

Comments

5

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

+1 You can use a ByteArrayOutputStream to help you build the data for the "file"
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
@ReidMac So what is the problems exactly?
@AndrewThompson Nothing, just providing more information, sorry. Trying this now.
0

Try creating a memory stream, your file is stored in the memory instead of the file system

Comments

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.