Here you can find the source of createFoldersIfNecessary(String workspacePath)
public static void createFoldersIfNecessary(String workspacePath)
//package com.java2s; /******************************************************************************* * Copyright (c) 2015 SAP and others./*from w ww.ja va 2s . c o m*/ * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * Contributors: * SAP - initial API and implementation *******************************************************************************/ import java.io.File; import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; public class Main { public static void createFoldersIfNecessary(String workspacePath) { int lastIndexOf = workspacePath.lastIndexOf(File.separator); if (lastIndexOf > 0) { String directory = workspacePath.substring(0, lastIndexOf); createFolder(directory); } } public static boolean createFolder(String workspacePath) { File folder = new File(workspacePath); if (!folder.exists()) { return folder.mkdirs(); } return true; } public static boolean exists(String location) { if ((location == null) || "".equals(location)) { return false; } Path path; try { path = FileSystems.getDefault().getPath(location); } catch (java.nio.file.InvalidPathException e) { return false; } return Files.exists(path); } }