Here you can find the source of mkdirs(File path)
Parameter | Description |
---|---|
path | a parameter |
Parameter | Description |
---|---|
IOException | if path not exists and could not be created. |
public static File mkdirs(File path) throws IOException
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { /**/*from w w w .j a v a2 s. c o m*/ * @param path * @throws IOException if path not exists and could not be created. */ public static File mkdirs(File path) throws IOException { path = getCleanAbsolutePath(path); // todo find parents and throw exception if the first existing is not a directory if (!path.exists()) { if (!path.mkdirs()) { throw new IOException("Could not mkdirs " + path.getAbsolutePath()); } // log.info("Created directory " + path.getAbsolutePath()); } return path; } /** * Makes "/tmp/a/b/c/./../.." into "/tmp/a/b/c" * * @param path * @return * @throws IOException */ public static File getCleanAbsolutePath(File path) throws IOException { path = new File(path.getAbsolutePath()); while (path.isDirectory()) { if (".".equals(path.getName())) { path = path.getParentFile(); } else if ("..".equals(path.getName())) { path = path.getParentFile(); } else { break; } } return path; } }