Code example for File

Methods: exists, getAbsolutePath, isDirectory, mkdir

0
import java.io.File; 
 
public class FileUtils { 
 
    public static  void makesureDir(final File dir) {
        if (!dir.exists()) {
            if (!dir.mkdir()) {
                throw new RuntimeException("Create directory failed:" + dir.getAbsolutePath());
            } 
        } 
        if (!dir.isDirectory()) {
            throw new RuntimeException("Path is not a directory:" + dir.getAbsolutePath());
        } 
    } 
 
}