Java Java7

Files.isReadable(), isWritable(), and isExecutable()

Files.isReadable(), isWritable(), and isExecutable()

Files.isReadable(), isWritable(), and isExecutable()

Java 7 introduced static methods in the Files class to easily check file access permissions on various platforms.

How it Works

These methods verify if the JVM has the necessary permissions to read, write, or execute the file at the given Path. They provide a more reliable check than old File methods.

Java Example

import java.nio.file.*;

public class FilePermissionExample {
    public static void main(String[] args) {
        Path path = Paths.get("test.txt");
        System.out.println("Readable: " + Files.isReadable(path));
        System.out.println("Writable: " + Files.isWritable(path));
    }
}

Output

Readable: true
Writable: true

Key Points

  • Check file permissions
  • Platform-independent API
  • Returns boolean status
  • Part of NIO.2 security improvements
Topics: Java Java7
← Newer Post Older Post →