Computer Science 225
Advanced Programming
Spring 2017, Siena College
FileMethods BlueJ Project
Click here to download a BlueJ project for FileMethods.
FileMethods Source Code
The Java source code for FileMethods is below. Click on a file name to download it.
import java.io.File;
import java.io.IOException;
/*
* Example FileMethods: demonstrate more of the methods of
* the java.io.File class
*
* Jim Teresco, Siena College, Computer Science 225, Spring 2017
*
* $Id: templateapp.java 2975 2016-08-30 02:35:29Z terescoj $
*/
public class FileMethods {
public static void main(String[] args) throws IOException {
// our program requires a file name parameter
if (args.length != 1) {
System.err.println("Usage: java FileMethods filename");
System.exit(1);
}
// now let's create a File object and see some things about this path
File f = new File(args[0]);
// There are many things we can do, so let's try some
System.out.println("toString of this file: " + f);
System.out.println(".exists(): " + f.exists());
System.out.println(".canRead(): " + f.canRead());
System.out.println(".canWrite(): " + f.canWrite());
System.out.println(".canExecute(): " + f.canExecute());
System.out.println(".getAbsolutePath(): " + f.getAbsolutePath());
System.out.println(".getCanonicalPath(): " + f.getCanonicalPath());
System.out.println(".getName(): " + f.getName());
System.out.println(".getParent(): " + f.getParent());
System.out.println(".isAbsolute(): " + f.isAbsolute());
System.out.println(".isDirectory(): " + f.isDirectory());
System.out.println(".isFile(): " + f.isFile());
System.out.println(".isHidden(): " + f.isHidden());
System.out.println(".lastModified(): " + f.lastModified());
System.out.println(".length(): " + f.length());
}
}