Java Path Copy nio createDirectoriesForFile(Path file)

Here you can find the source of createDirectoriesForFile(Path file)

Description

Creates all missing directories for the current path.

License

Open Source License

Parameter

Parameter Description
file the file for which all needed directories should be created

Exception

Parameter Description
RuntimeException if the directories could not be created

Declaration

public static void createDirectoriesForFile(Path file) 

Method Source Code


//package com.java2s;
/*/* w  ww .  j  av  a2s.  co  m*/
 *     BasePlugin
 *   Copyright (C) 2014 Viciouss <http://www.doncarnage.de>
 *
 *   This program is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU Lesser General Public
 *   License as published by the Free Software Foundation; either
 *   version 3 of the License, or (at your option) any later version.
 *
 *   This program 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
 *   Lesser General Public License for more details.
 *
 *   You should have received a copy of the GNU Lesser General Public
 *   License along with this library; if not, write to the Free Software
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
 *   USA
 */

import java.io.IOException;

import java.nio.file.Files;
import java.nio.file.Path;

public class Main {
    /**
     * Creates all missing directories for the current path. This is to prevent an exception that would get thrown if the path contains a file in a directory
     * that does not yet exist as private logging files could and actually get by default stored in the log files subdirectory of the plugins own directory.
     *
     * @param file the file for which all needed directories should be created
     * @throws RuntimeException if the directories could not be created
     */
    public static void createDirectoriesForFile(Path file) {
        Path parent = file.getParent();
        try {
            Files.createDirectories(parent);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

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