Java Path File Write nio canWrite(Path path)

Here you can find the source of canWrite(Path path)

Description

can Write

License

Apache License

Declaration

public static boolean canWrite(Path path) 

Method Source Code

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

import java.nio.file.Files;
import java.nio.file.LinkOption;

import java.nio.file.Path;

public class Main {
    public static boolean canWrite(Path path) {
        if (!isFile(path)) {
            return false;
        }/*from   w  w w  .j  ava  2s . c o m*/

        try {
            //## todo: find a better way, Files.isWritable() does not work e.g., returns true for ZipPath, which is wrong
            return path.toFile().canWrite();
        } catch (UnsupportedOperationException e) {
            return false;
        }
    }

    public static boolean isFile(Path path, LinkOption... options) {
        return Files.isRegularFile(path, options);
    }
}

Related

  1. checkFilePermissions(final String filepath, final boolean canRead, final boolean canWrite)
  2. compareTable(final String table, final List d1, final List d2, final BufferedWriter errors)
  3. isWritePermission(Path p)
  4. newBufferedWriter(Path path)