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
2016-12-30 17:23:13 -08:00
// (c)2017 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.
2016-09-23 13:23:35 -06:00
// Visit http://OnJava8.com for more book information.
2015-12-02 09:20:27 -08:00
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()
2016-12-31 14:57:31 -08:00
.supportedFileAttributeViews().contains("posix"))
2015-12-02 09:20:27 -08:00
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
FileStore: Teenyverse (C:)
LastModified: : 2017-05-02T21:19:06.828604Z
Owner: TEENYVERSE\bruce (User)
2015-12-02 09:20:27 -08:00
ContentType: null
SymbolicLink: false
*/