Here you can find the source of makeDirectory(final CharSequence aPath)
Parameter | Description |
---|---|
aPath | base directory path |
Parameter | Description |
---|---|
IOException | The directory already exists or can't be created |
public static File makeDirectory(final CharSequence aPath) throws IOException
//package com.java2s; /**//w w w . j a v a2 s . co m * Copyright 2014 isandlaTech * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.File; import java.io.IOException; public class Main { /** * Returns a valid directory from the given path (it may return the parent * directory). * * @param aPath * base directory path * @return A valid directory path * * @throws IOException * The directory already exists or can't be created */ public static File makeDirectory(final CharSequence aPath) throws IOException { final File directory = new File(aPath.toString()); if (!directory.exists()) { // Create directory if needed if (!directory.mkdirs()) { throw new IOException("Directory not created. Already existing ?"); } } else if (!directory.isDirectory()) { // A node already has this name throw new IOException("'" + aPath + "' is not a valid directory."); } return directory; } }