Java Utililty Methods Path Create nio

List of utility methods to do Path Create nio

Description

The list of methods to do Path Create nio are organized into topic(s).

Method

voidcreateFile(Path path)
create File
File file = path.toFile();
if (file.exists()) {
    file.delete();
file.createNewFile();
voidcreateFile(String filePath, String content)
create File
File file = new File(filePath);
try {
    if (!file.exists()) {
        if (!file.getParentFile().exists()) {
            file.getParentFile().mkdirs();
        file.createNewFile();
    FileOutputStream fos = new FileOutputStream(file);
    fos.write(content.getBytes(Charset.forName("UTF-8")));
    fos.flush();
    fos.close();
} catch (IOException e) {
    e.printStackTrace();
booleancreateFile(String workspacePath)
create File
createFoldersIfNecessary(workspacePath);
File file = new File(workspacePath);
if (!file.exists()) {
    return file.createNewFile();
return true;
PathcreateFileForReport(Path reportDir, String filePrefix, String fileSuffix)
create File For Report
Path reportFile = reportDir.resolve(filePrefix + "_validation_result." + fileSuffix);
for (int i = 1; Files.exists(reportFile); i++) {
    reportFile = reportDir.resolve(filePrefix + "(" + i + ")_validation_result." + fileSuffix);
return reportFile;
voidcreateFileFromText(String sourceText, IPath path)
Creates a file from input string text.
Preconditions.checkArgument(path.isAbsolute());
Path file = FileSystems.getDefault().getPath(path.toOSString());
Files.write(file, sourceText.getBytes());
voidcreateFileIfNotExist(Path path)
create File If Not Exist
try (FileChannel f = FileChannel.open(path, StandardOpenOption.CREATE, StandardOpenOption.WRITE)) {
booleancreateFileIfNotExists(Path path)
create File If Not Exists
if (Files.notExists(path) || !path.toFile().exists()) {
    Files.createFile(path); 
    return true;
return false;
URIcreateFileRelativeToClasspath(String resourceName)
create File Relative To Classpath
final File file = Paths.get(new File("").getAbsolutePath(), resourceName).toFile();
file.mkdirs();
if (!file.exists()) {
    file.delete();
file.createNewFile();
return file.toURI();
PathcreateFileWithContents(String pathString, String contents)
create File With Contents
Path path = FileSystems.getDefault().getPath(pathString);
if (exists(path)) {
    throw new IOException("File " + pathString + " already exists.");
} else {
    createFile(path);
try (BufferedWriter out = newBufferedWriter(path, Charset.defaultCharset())) {
    out.write(contents);
...
booleancreateFolder(String workspacePath)
create Folder
File folder = new File(workspacePath);
if (!folder.exists()) {
    return folder.mkdirs();
return true;