Java mkdir makeDirectory(final CharSequence aPath)

Here you can find the source of makeDirectory(final CharSequence aPath)

Description

Returns a valid directory from the given path (it may return the parent directory).

License

Apache License

Parameter

Parameter Description
aPath base directory path

Exception

Parameter Description
IOException The directory already exists or can't be created

Return

A valid directory path

Declaration

public static File makeDirectory(final CharSequence aPath) throws IOException 

Method Source Code

//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;
    }
}

Related

  1. makeDirectory(File file)
  2. makeDirectory(File file)
  3. makeDirectory(File file)
  4. makedirectory(File outputDirectory, String directoryName)
  5. makeDirectory(File testDir )
  6. makeDirectory(final File file, final String extension)
  7. makeDirectory(String directory)
  8. makeDirectory(String directoryName)
  9. makeDirectory(String directoryPath)