Java Path Create nio createFile(String workspacePath)

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

Description

create File

License

Apache License

Declaration

public static boolean createFile(String workspacePath) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.File;

import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;

public class Main {
    public static boolean createFile(String workspacePath) throws IOException {
        createFoldersIfNecessary(workspacePath);
        File file = new File(workspacePath);
        if (!file.exists()) {
            return file.createNewFile();
        }//w  w w . ja  v a 2s  . co m
        return true;
    }

    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 exists(String repositoryName) {
        if (repositoryName == null || "".equals(repositoryName)) {
            return false;
        }
        Path path;
        try {
            path = FileSystems.getDefault().getPath(repositoryName);
        } catch (java.nio.file.InvalidPathException e) {
            return false;
        }
        return Files.exists(path);
    }

    public static boolean createFolder(String workspacePath) {
        File folder = new File(workspacePath);
        if (!folder.exists()) {
            return folder.mkdirs();
        }
        return true;
    }
}

Related

  1. createFile(Path path)
  2. createFile(Path path)
  3. createFile(Path path)
  4. createFile(Path path)
  5. createFile(String filePath, String content)
  6. createFileForReport(Path reportDir, String filePrefix, String fileSuffix)
  7. createFileFromText(String sourceText, IPath path)
  8. createFileIfNotExist(Path path)
  9. createFileIfNotExists(Path path)