Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create tmp file name with out creating file

Tags:

java

file

file-io

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    } 
like image 934
Michał Ziober Avatar asked Aug 18 '09 12:08

Michał Ziober


People also ask

How do I create a TMP file?

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.

How do you create a temp file in Java without the random number appended to the file?

Just check the return value of temp. createNewFile() . Read the specification of createNewFile() . The important word is atomic.

Why .TMP files are created?

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.

How do I create a temp folder?

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".


1 Answers

Use a GUID

  • http://java.sun.com/j2se/1.5.0/docs/api/java/util/UUID.html
  • http://en.wikipedia.org/wiki/Globally_Unique_Identifier
like image 51
John Oxley Avatar answered Sep 19 '22 06:09

John Oxley