Here you can find the source of createDirectories(Path thePath, FileAttribute>... theAttributes)
static public void createDirectories(Path thePath, FileAttribute<?>... theAttributes)
//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()); } }