Java Path Copy nio createDirectories(Path thePath, FileAttribute... theAttributes)

Here you can find the source of createDirectories(Path thePath, FileAttribute... theAttributes)

Description

create Directories

License

Open Source License

Declaration

static public void createDirectories(Path thePath,
             FileAttribute<?>... theAttributes) 

Method Source Code

//package com.java2s;
/*/*from  w  w  w .  j  a va2 s  .  com*/
 * Copyright (c) 2013 christianr.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v3
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl-3.0.html
 * 
 * Contributors:
 *     christianr - initial API and implementation
 */

import java.io.IOException;

import java.nio.file.FileAlreadyExistsException;

import java.nio.file.Files;

import java.nio.file.Path;

import java.nio.file.attribute.FileAttribute;

public class Main {
    static public void createDirectories(Path thePath,
            FileAttribute<?>... theAttributes) {
        if (thePath == null)
            return;

        if (fileExtension(thePath) != null) {
            thePath = thePath.getParent();
            if (thePath == null)
                return;
        }

        try {
            Files.createDirectories(thePath, theAttributes);
        } catch (FileAlreadyExistsException e) {

        } catch (IOException e) {

            throw new RuntimeException(e);
        }
    }

    /**
     * Gets the extension of the given file.
     * @param thePath path of the file to check the extension
     * @return the extension of the file
     */
    public static String fileExtension(final Path thePath) {
        if (thePath == null)
            return null;
        if (thePath.getFileName() == null)
            return null;
        String myPathString = thePath.getFileName().toString();
        if (myPathString.lastIndexOf(".") < 0)
            return null;
        return myPathString.substring(myPathString.lastIndexOf(".") + 1,
                myPathString.length());
    }
}

Related

  1. copyResources(final URL source, final Path destination)
  2. copyToDir(Path source, Path targetDir, CopyOption... options)
  3. copyTree(final Path source, final Path target)
  4. createDirectories(Path currentRestorePath)
  5. createDirectories(Path path, FileAttribute... attrs)
  6. createDirectoriesForFile(Path file)
  7. createDirectoriesForOutput(File output)
  8. createDirectoriesIfNeeded(Path directory)
  9. createDirectoriesIfNotExists(Path path)