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.
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.
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.
Just check the return value of temp. createNewFile() . Read the specification of createNewFile() . The important word is atomic.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With