Java Path Create nio createDirectory(Path parent, String name)

Here you can find the source of createDirectory(Path parent, String name)

Description

Create a directory (recursively)

License

Open Source License

Parameter

Parameter Description
parent a parameter
name a parameter

Declaration

public static Path createDirectory(Path parent, String name) 

Method Source Code


//package com.java2s;
/*//from  ww  w.  j a  v  a  2  s.  c o  m
 * EXELIXI
 *
 * Copyright (C) 2017 EPFL SCI-STI-MM
 *
 * This file is part of EXELIXI.
 *
 * EXELIXI is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * EXELIXI is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with EXELIXI. If not, see <http://www.gnu.org/licenses/>.
 *
 * Additional permission under GNU GPL version 3 section 7
 *
 * If you modify this Program, or any covered work, by linking or combining it
 * with Eclipse (or a modified version of Eclipse or an Eclipse plugin or
 * an Eclipse library), containing parts covered by the terms of the
 * Eclipse Public License (EPL), the licensors of this Program grant you
 * additional permission to convey the resulting work.  Corresponding Source
 * for a non-source form of such a combination shall include the source code
 * for the parts of Eclipse libraries used as well as that of the covered work.
 *
 */

import java.io.File;

import java.nio.file.Path;

public class Main {
    /**
     * Create a directory (recursively)
     *
     * @param parent
     * @param name
     * @return
     */
    public static Path createDirectory(Path parent, String name) {
        Path path = null;
        try {
            File directory = new File(parent.toFile(), name);
            if (!directory.exists()) {
                if (directory.mkdirs()) {
                    path = directory.toPath();
                }
            } else if (directory.isDirectory()) {
                path = directory.toPath();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return path;
    }
}

Related

  1. createChecksums(final Path file, final Map functions)
  2. createClassWithDepsNextExtra(int index, Path dir)
  3. createDir(Path p)
  4. createDirectoriesIfRequired(@Nonnull Path path)
  5. createDirectory(final Path parent, final String folderName)
  6. createDirectory(Path path)
  7. createDirIfDoesNotExist(String websitesDirPath)
  8. createEmptyResourceFile(Path path)
  9. createFile(File root, String path, String filename, String value)