OnJava8-Examples/files/PathAnalysis.java

57 lines
1.7 KiB
Java
Raw Normal View History

2015-12-02 09:20:27 -08:00
// files/PathAnalysis.java
2015-12-15 11:47:04 -08:00
// (c)2016 MindView LLC: see Copyright.txt
2015-12-02 09:20:27 -08:00
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ 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);
}
2016-01-25 18:05:55 -08:00
public static void
main(String[] args) throws IOException {
2015-12-02 09:20:27 -08:00
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
2016-07-27 11:12:11 -06:00
size: 1630
2016-07-22 14:45:35 -06:00
FileStore: SSD (C:)
2016-07-27 11:12:11 -06:00
LastModified: : 2016-07-27T15:52:49.898848Z
2016-07-22 14:45:35 -06:00
Owner: MINDVIEWTOSHIBA\Bruce (User)
2015-12-02 09:20:27 -08:00
ContentType: null
SymbolicLink: false
*/