Return a file with the given filename creating the necessary directories if not present in Java
Description
The following code shows how to return a file with the given filename creating the necessary directories if not present.
Example
//from w ww . j av a 2 s. c o m
import java.io.File;
public class Main {
public static File createFile(File destDir, String filename) {
File file = new File(destDir, filename);
File parent = file.getParentFile();
if (parent != null)
parent.mkdirs();
return file;
}
}