Java Files isReadable() Method

Beginner
6 min read
Updated: Nov 2026
3 examples
Java 7+

Definition

In Java, Files.isReadable(path) returns true when the file exists and the current user may read it. It checks the operating system's permissions without opening the file.

A missing file returns false, so the method also works as a combined "exists and readable" check. A true answer is not a promise: permissions can change, or the file can disappear, before you read it.

A static method of the final utility class java.nio.file.Files, available since Java 7. Call it on the class name, as in Files.isReadable(...), after import java.nio.file.Files;. You never create a Files object.

Syntax

Pass the path; there are no options:

Java
if (Files.isReadable(input)) {
    List<String> lines = Files.readAllLines(input);
}
CallWhat it does
Files.isReadable(p)Exists and may be read.
Files.isWritable(p)Exists and may be written.
Files.isExecutable(p)Exists and may be executed (or searched, for a folder).

Since Java 7. Folders work too: a readable folder can be listed. Results depend on who runs the program; on Linux and macOS the root user may read almost everything.

Library declarations
Java
public static boolean isReadable(Path path)

Parameters

ParameterDescription
pathThe file or folder to test.

Return Value

Return ValueDescription
trueIt exists and the JVM has read access.
falseMissing, not readable, or unknown.

Compare with Similar Methods

Permission checks:

MethodHow it differs
isWritable()Same idea for writing.
getPosixFilePermissions()Shows the actual permission bits.
exists()Ignores permissions.

Java Examples

Example 1 — Readable Means "Exists and Allowed"

A new file and the temp folder are readable; a missing file is not.

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

public class IsReadableBasic {
    public static void main(String[] args) throws IOException {
        Path dir = Files.createTempDirectory("demo");
        Path file = Files.createFile(dir.resolve("prices.csv"));
        System.out.println("prices.csv: " + Files.isReadable(file));
        System.out.println("temp folder: " + Files.isReadable(dir));
        System.out.println("missing.csv: " + Files.isReadable(dir.resolve("missing.csv")));
        Files.delete(file);
        Files.delete(dir);
    }
}

How It Works

  1. You own what you create. The program created prices.csv, so it has read permission by default.
  2. Folders are readable too. For a folder, readable means its entries may be listed.
  3. Missing counts as unreadable. The method returns false rather than throwing for a file that does not exist.

Example 2 — Take Away Read Permission on Linux or macOS

Set the permissions to write-only, check again, then restore them.

Java
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.PosixFilePermissions;

public class IsReadablePosix {
    public static void main(String[] args) throws IOException {
        Path dir = Files.createTempDirectory("demo");
        Path file = dir.resolve("secret.txt");
        Files.write(file, "pin=1234".getBytes(StandardCharsets.UTF_8));
        System.out.println("Readable at first: " + Files.isReadable(file));
        if (FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) {
            Files.setPosixFilePermissions(file, PosixFilePermissions.fromString("-w-------"));
            System.out.println("After removing read: " + Files.isReadable(file));
            Files.setPosixFilePermissions(file, PosixFilePermissions.fromString("rw-------"));
        } else {
            System.out.println("No POSIX permissions on this system");
        }
        Files.delete(file);
        Files.delete(dir);
    }
}

How It Works

  1. Readable at the start. A freshly written file can be read by its owner.
  2. Write-only permissions. -w------- keeps only the owner's write bit, so the read check now fails for a normal user.
  3. Root is different. Running as root on Linux would still print true, because root bypasses read permissions; that is why the output is labelled "normal user".

Example 3 — Explain Why a File Cannot Be Read

Use isReadable for a friendly message, but keep a catch for problems that appear after the check.

Java
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;

public class IsReadableSafeRead {
    static String readOrExplain(Path p) {
        if (!Files.isReadable(p)) {
            return p.getFileName() + ": cannot read (missing or no permission)";
        }
        try {
            return p.getFileName() + ": " + new String(Files.readAllBytes(p), StandardCharsets.UTF_8);
        } catch (IOException e) {
            return p.getFileName() + ": read failed";
        }
    }

    public static void main(String[] args) throws IOException {
        Path dir = Files.createTempDirectory("demo");
        Path motd = dir.resolve("motd.txt");
        Files.write(motd, "Welcome!".getBytes(StandardCharsets.UTF_8));
        System.out.println(readOrExplain(motd));
        System.out.println(readOrExplain(dir.resolve("absent.txt")));
        Files.delete(motd);
        Files.delete(dir);
    }
}

How It Works

  1. Friendly first. The check catches the common cases early and returns a clear message instead of an exception.
  2. Still defensive. The file could be deleted between the check and the read, so the actual read keeps its own catch.
  3. Two results. motd.txt prints its content, and absent.txt gets the explanation.

Frequently Asked Questions

That the file exists and that the current user has permission to read it, according to the operating system.
No. It only checks access rights, so a later read can still fail.
On Linux and macOS the root user bypasses normal read permissions, and Java reports what the operating system allows.
false, without an exception.
On Linux and macOS use Files.setPosixFilePermissions with a set that has no read bits, such as PosixFilePermissions.fromString("-w-------"). On Windows read access is controlled by access-control lists.

Next: Files.isRegularFile()

Check whether a path exists and is an ordinary file (not a folder or device).

isRegularFile() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful