/* DemoFileObject.java 2013-11-22 David G. Klick Demonstrates the use of the File object. */ import java.io.File; import java.util.Scanner; public class DemoFileObject { public static void main(String[] args) { Scanner kbd = new Scanner(System.in); String filename = null; StringBuilder msg = new StringBuilder(); do { msg.setLength(0); System.out.print("Enter a filename (ENTER to quit): "); filename = kbd.nextLine(); if (filename.length() > 0) { File file = new File(filename); if (!file.exists()) { msg.append("File does not exist\n"); } else { if (file.canRead()) msg.append("File is readable\n"); if (file.canWrite()) msg.append("File is writeable\n"); if (file.canExecute()) msg.append("File is executable\n"); if (file.isDirectory()) msg.append("File is a directory\n"); if (file.isFile()) msg.append("File is a regular file\n"); msg.append("File is " + file.length() + " bytes long\n"); } System.out.println(msg.toString()); } } while (filename.length() != 0); } }