Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

file

io

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.

like image 292
Alexander Mills Avatar asked Oct 16 '13 20:10

Alexander Mills


People also ask

How do you create a new file object in Java?

Example 1: Java Program to Create a File java is equivalent to // currentdirectory/JavaFile. java File file = new File("JavaFile. java"); We then use the createNewFile() method of the File class to create new file to the specified path.

What method is used to create an empty file in Java?

A new empty file with the required abstract path name can be created using the method java. io. File. createNewFile().


1 Answers

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.

like image 114
Claudiu Avatar answered Oct 06 '22 20:10

Claudiu