Java Reference
In-Depth Information
path,
BasicFileAttributes.class);
if(attr.isDirectory())
System.out.println(path.getFileName() + " is a directory.");
else if(attr.isRegularFile()) {
System.out.println(path.getFileName() + " is a file
containing " +
attr.size() + "
bytes.");
}
System.out.println(path + " was created "+ attr.creationTime());
System.out.println(path + " was last accessed "+
attr.lastAccessTime());
System.out.println(path + " was last modified "+
attr.lastModifiedTime());
System.out.println(path + " is "+ attr.size() + " bytes.");
} catch(IOException e) {
System.err.println(e);
}
}
}
TryPath.java
On my machine, the example produces the following output:
garbage.java has 1 elements.
garbage.java is a relative path.
D:\Beginning Java SE 7\Projects\TryPath\classes\garbage.java does not
exist.
D:\Beginning Java SE 7\Projects\TryPath\classes has 4 elements.
D:\Beginning Java SE 7\Projects\TryPath\classes is an absolute path.
The parent path is D:\Beginning Java SE 7\Projects\TryPath
The root is D:\
classes is a directory.
D:\Beginning Java SE 7\Projects\TryPath\classes
was created
2011-03-23T18:33:22.217037Z
D:\Beginning Java SE 7\Projects\TryPath\classes was last accessed
2011-03-23T18:59:28.113457Z
D:\Beginning Java SE 7\Projects\TryPath\classes was last modified
2011-03-23T18:59:28.113457Z
D:\Beginning Java SE 7\Projects\TryPath\classes is 0 bytes.
D:\Beginning Java SE 7\Projects\TryPath\src\TryPath.java has 5
elements.
D:\Beginning Java SE 7\Projects\TryPath\src\TryPath.java is an
absolute path.
The parent path is D:\Beginning Java SE 7\Projects\TryPath\src
Search WWH ::




Custom Search