简体   繁体   中英

How to create File object in Java without saving to hard disk

Can you create a File object in Java without saving to hard disk?

All the constructors for java.io.File seem to take info about a location on disk.

A File object is not a file. It is a path to a location on disk with some utility methods. This location need not exist to have a valid file. For instance, you can do File#createNewFile to create a physical file after creating a File object that would point to that pathname on disk.

Use URL and related classes to read remotely, or some sort of java.nio.ByteBuffer to store file data in memory.

Even if you create a file object, the file itself does not need to exist on disk.

When constructing the java object, you need to specify a location of the file absolute or relative to the current directory, but the file itself does not need to exist on disk.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM