Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 959
  • Last Modified:

How to temp filename in Java?

Is there any function in Java to help me get a unique filename in java?

What I looking for something similar to createtmpfile() call in windows,
which basically creats a unique file name which youcan use.
0
kumarana
Asked:
kumarana
1 Solution
 
davidmorandCommented:
Yes there is one,

In the class java.io.File you have the following methods:

static File createTempFile(String prefix, String suffix)

Creates an empty file in the default temporary-file directory, using the given prefix and suffix to generate its name.

static File createTempFile(String prefix, String suffix, File directory)

Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name.

With them you can create a temporary file.

You then need to call the method deleteOnExit() on each temporary file if you want them to be deleted when you exit the program.

You can find more info in the doc of this class.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now