Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.PrintStream;
- public class TryJavaFileDeleteOnExit {
- public static void main(String[] args) {
- try {
- File tempFolder = File.createTempFile("myTempFolder", "");
- tempFolder.delete();
- tempFolder.mkdirs();
- // deleteOnExit() does NOT work, temp-folder and files will NOT be deleted
- tempFolder.deleteOnExit();
- System.out.println("tempFolder path = " + tempFolder.getAbsolutePath());
- for(int i=1; i<=3; i++) {
- File fileInTempFolder = new File(tempFolder, "fileInTempFolder_" + i + ".txt");
- PrintStream fileOut = new PrintStream(new FileOutputStream(fileInTempFolder));
- fileOut.println("hell0!");
- fileOut.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement