Solved

How to temp filename in Java?

Posted on 2000-02-29
1
945 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jboss wildfly 10.1 10 398
What's wrong with this code? 4 34
Crystal Reports Licensing Questions 4 56
activeMQ Queue Messages Enqueued and Messages Dequeued 1 24
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.

680 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