I write application in Java using SWT. I would like to create unique file name. But I do not want create it on hard drive. Additional functionality: I want to create unique file name in specify folder.
public String getUniqueFileName(String directory, String extension) { //create unique file name }
To create and use a temporary file The application opens the user-provided source text file by using CreateFile. The application retrieves a temporary file path and file name by using the GetTempPath and GetTempFileName functions, and then uses CreateFile to create the temporary file.
Just check the return value of temp. createNewFile() . Read the specification of createNewFile() . The important word is atomic.
The main purpose of creating temporary files is to free up memory on your computer. By caching data, memory can be used elsewhere. Temporary files also help to prevent data loss. For example, Microsoft Word ensures that a document can be restored from a TMP file in case of a crash or an expected power cut.
Open your File Explorer (it's usually the first button on your desktop taskbar, looks like a folder). Go to the "This PC" section on the left, and then double-click your C: drive. On the Home tab at the top, click "New Folder" and name it "Temp".
Use a GUID
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With