I want to create a .dat file in java which doesn’t exist. I don’t know how to manually create it either. I know that the following code:
File f = new File(file);
is used for the file, but what exactly is the code for a file which doesn’t exist. In other words create a new file.
A statement like
File f = new File(file);will not create a file on disk. Classjava.io.Fileonly represents a file path, not the actual file on disk.To create a new file, open a
FileOutputStreamfor it, which you can then use to write data to the file.