Java Reference
In-Depth Information
public
public class
class FileStatus
FileStatus {
public
public static
static void
void main ( String [] argv ) throws
throws IOException {
// Ensure that a filename (or something) was given in argv[0]
iif ( argv . length == 0 ) {
System . err . println ( "Usage: FileStatus filename" );
System . exit ( 1 );
}
for
for ( String a : argv ) {
status ( a );
}
}
public
public static
throws IOException {
System . out . println ( "---" + fileName + "---" );
static void
void status ( String fileName ) throws
// Construct a File object for the given file.
File f = new
new File ( fileName );
// See if it actually exists
iif (! f . exists ()) {
System . out . println ( "file not found" );
System . out . println ();
// Blank line
return
return ;
}
// Print full name
System . out . println ( "Canonical name " + f . getCanonicalPath ());
// Print parent directory if possible
String p = f . getParent ();
iif ( p != null
null ) {
System . out . println ( "Parent directory: " + p );
}
// Check if the file is readable
iif ( f . canRead ()) {
System . out . println ( "File is readable." );
}
// Check if the file is writable
iif ( f . canWrite ()) {
System . out . println ( "File is writable." );
}
// Report on the modification time.
Date d = new
new Date ( f . lastModified ());
System . out . println ( "Last modified " + d );
// See if file, directory, or other. If file, print size.
iif ( f . isFile ()) {
Search WWH ::




Custom Search