Java Path Create nio createFoldersIfNecessary(String workspacePath)

Here you can find the source of createFoldersIfNecessary(String workspacePath)

Description

create Folders If Necessary

License

Open Source License

Declaration

public static void createFoldersIfNecessary(String workspacePath) 

Method Source Code

//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);
    }
}

Related

  1. createFileIfNotExist(Path path)
  2. createFileIfNotExists(Path path)
  3. createFileRelativeToClasspath(String resourceName)
  4. createFileWithContents(String pathString, String contents)
  5. createFolder(String workspacePath)
  6. createFullURI(String val, Path parent)
  7. createGlobMatcher(final Path path)
  8. createHeader(Path newFile)
  9. createHiddenFile(String filePath)