If you can use external libraries, there are several:
If an entire library seems a hassle, creating a JNI wrapper that calls the lstat
C function and returns the access mode takes you about 10 minutes. Here's a tutorial that creates such a wrapper for the isatty
and ttyname
functions.