How to create temp directory in heroku/docker using Java? How to create temp directory in heroku/docker using Java? docker docker

How to create temp directory in heroku/docker using Java?


 File tempDirectory = new File(new File(System.getProperty("java.io.tmpdir")), "files");        if(tempDirectory.exists()){            System.out.println("something");        }else{            tempDirectory.mkdirs();        }        File file = new File(tempDirectory.getAbsolutePath()+"/abcd.txt");        if(!file.exists()){            file.createNewFile();        }        String file2= new File(tempDirectory.getAbsolutePath()+"/something.txt").getAbsolutePath();        System.out.println(file2);

Works totally fine at my end. The only problem you might be having is

String filePath = new File(tempDirectory.getAbsolutePath() + "/temp.exe").getAbsolutePath();

This doesn't create the file in the temp directory you have created. It just returns the absolute path if it was to be saved in the directory mentioned. This might be the reason you are getting not found error. Try actually saving by using

file.transferTo(wherefileneedstobesavedlocation);