57 lines
1.7 KiB
Java
57 lines
1.7 KiB
Java
// files/PathAnalysis.java
|
|
// (c)2017 MindView LLC: see Copyright.txt
|
|
// We make no guarantees that this code is fit for any purpose.
|
|
// Visit http://OnJava8.com for more book information.
|
|
import java.nio.file.*;
|
|
import java.io.IOException;
|
|
|
|
public class PathAnalysis {
|
|
static void say(String id, Object result) {
|
|
System.out.print(id + ": ");
|
|
System.out.println(result);
|
|
}
|
|
public static void
|
|
main(String[] args) throws IOException {
|
|
System.out.println(System.getProperty("os.name"));
|
|
Path p =
|
|
Paths.get("PathAnalysis.java").toAbsolutePath();
|
|
say("Exists", Files.exists(p));
|
|
say("Directory", Files.isDirectory(p));
|
|
say("Executable", Files.isExecutable(p));
|
|
say("Readable", Files.isReadable(p));
|
|
say("RegularFile", Files.isRegularFile(p));
|
|
say("Writable", Files.isWritable(p));
|
|
say("notExists", Files.notExists(p));
|
|
say("Hidden", Files.isHidden(p));
|
|
say("size", Files.size(p));
|
|
say("FileStore", Files.getFileStore(p));
|
|
say("LastModified: ", Files.getLastModifiedTime(p));
|
|
say("Owner", Files.getOwner(p));
|
|
say("ContentType", Files.probeContentType(p));
|
|
say("SymbolicLink", Files.isSymbolicLink(p));
|
|
if(Files.isSymbolicLink(p))
|
|
say("SymbolicLink", Files.readSymbolicLink(p));
|
|
if(FileSystems.getDefault()
|
|
.supportedFileAttributeViews().contains("posix"))
|
|
say("PosixFilePermissions",
|
|
Files.getPosixFilePermissions(p));
|
|
}
|
|
}
|
|
/* Output:
|
|
Windows 10
|
|
Exists: true
|
|
Directory: false
|
|
Executable: true
|
|
Readable: true
|
|
RegularFile: true
|
|
Writable: true
|
|
notExists: false
|
|
Hidden: false
|
|
size: 1630
|
|
FileStore: SSD (C:)
|
|
LastModified: : 2016-07-27T15:52:49.898848Z
|
|
Owner: MINDVIEWTOSHIBA\Bruce (User)
|
|
ContentType: null
|
|
SymbolicLink: false
|
|
*/
|