How to create a temporary directory (folder) in Java

1 Answer

0 votes
import java.nio.file.Path;
import java.nio.file.Files;
 
public class MyClass {
 
    public static void main(String args[]) throws Exception {  
        Path tempDir = Files.createTempDirectory("prefix-");

        System.out.println(tempDir); 
    }
}
         
         
         
         
/*
run:
         
/tmp/prefix-11465374821025199333
 
*/

 



answered Oct 8, 2023 by avibootz
edited Oct 8, 2023 by avibootz

Related questions

2 answers 264 views
1 answer 183 views
183 views asked Jul 2, 2020 by avibootz
2 answers 316 views
1 answer 214 views
1 answer 225 views
225 views asked Aug 2, 2018 by avibootz
2 answers 251 views
251 views asked Sep 28, 2015 by avibootz
3 answers 411 views
...