Java's createNewFile() - will it also create directories? Java's createNewFile() - will it also create directories? java java

Java's createNewFile() - will it also create directories?


No.
Use tmp.getParentFile().mkdirs() before you create the file.


File theDir = new File(DirectoryPath);if (!theDir.exists()) theDir.mkdirs();


File directory = new File(tmp.getParentFile().getAbsolutePath());directory.mkdirs();

If the directories already exist, nothing will happen, so you don't need any checks.