Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I create a temporary folder in java 6? [duplicate]

Possible Duplicate:
Create a temporary directory in Java

Duplicate: stackoverflow.com/questions/375910

Is there a way of creating a temporary folder in java ? I know of File's static method createTempFile, but this will only give me a temporary file.

like image 266
Geo Avatar asked May 03 '09 16:05

Geo


People also ask

How do I create a temp folder?

Use mktemp -d . It creates a temporary directory with a random name and makes sure that file doesn't already exist. You need to remember to delete the directory after using it though. Save this answer.

How do I create a temp folder in Junit?

Example of usage: public static class HasTempFolder { @Rule public TemporaryFolder folder= new TemporaryFolder(); @Test public void testUsingTempFolder() throws IOException { File createdFile= folder. newFile("myfile. txt"); File createdFolder= folder.

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

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


1 Answers

I've never seen a good solution for this, but this is how I've done it.

File temp = File.createTempFile("folder-name","");
temp.delete();
temp.mkdir();
like image 75
John Meagher Avatar answered Oct 13 '22 19:10

John Meagher