Files Readable Writable Access Probes
Probe files with Files.isReadable, isWritable, and isExecutable; they return false on missing files instead of throwing, and executability is platform-specific.
Code
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
public class FileAccessProbes {
public static void main(String[] args) throws IOException {
Path config = Files.createTempFile("app-config", ".txt");
Files.writeString(config, "retries=3\n");
System.out.println("readable: " + Files.isReadable(config));
System.out.println("writable: " + Files.isWritable(config));
// access 探针之一:可执行判定有平台语义——POSIX 看 x 位(临时 .txt
// 未置 x 位,输出 false);Windows 走 FILE_EXECUTE 的 ACL 检查,
// 用户自建文件通常被授予执行权,可能输出 true
System.out.println("executable: " + Files.isExecutable(config));
Files.delete(config);
// 文件不存在时 probes 返回 false,不抛异常
System.out.println("after delete readable: " + Files.isReadable(config));
System.out.println("after delete writable: " + Files.isWritable(config));
System.out.println("after delete executable: " + Files.isExecutable(config));
}
}Inside the snippet
All of the logic lives in the class FileAccessProbes.
What to watch for
- No dependency machinery at all — no registry file and no lockfile entry.
Using it
The demo output is labeled (readable:, writable:, executable:), so the printed lines read as a trace of the operations that ran.
The key statements, annotated
Path config = Files.createTempFile("app-config", ".txt");
Files.writeString(config, "retries=3\n");
Files.delete(config);
Interactive Tools for This Topic
Argon2id Hash InfoEstimate Argon2id password-hash latency and memory usage, and check your parameters against OWASP 2024 minimum and recommended settings.bcrypt Cost EstimatorEstimate bcrypt cost factor latency and brute-force resistance, and get a recommended cost for your target hash time and attacker throughput.CORS Header Policy DebuggerSimulate browser CORS preflight and credential policies against server response headers to pinpoint blocked origins, methods, or headers and fix them.CSP Header BuilderBuild a Content-Security-Policy header from per-directive sources, skipping empty ones and rejecting a blanket wildcard.
FAQ
- What does Files Readable Writable Access Probes print when run?
- Invoke the file as-is — the `readable:`, `writable:`, `executable:` prefixes identify which step printed each line.
Report a problem with this exampleOpens a pre-filled issue on GitHub.