Solved

How to temp filename in Java?

Posted on 2000-02-29
1
940 Views
Last Modified: 2008-02-26
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
Comment
Question by:kumarana
1 Comment
 

Accepted Solution

by:
davidmorand earned 200 total points
ID: 2569296
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
splitOdd10 challenge 5 81
mapAB Challlenge 35 128
sites similar to codingbat to improve coding hanson skills 3 41
simple java question 3 44
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
The viewer will learn how to implement Singleton Design Pattern in Java.
This video teaches viewers about errors in exception handling.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now