import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * Demonstrate using File objects and FileInputStreams in Java.
 * 
 * @author CSCI209
 * 
 */
public class FileTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// String basedir =
		// "/Users/sprenkle/Documents/WLU/CS209/";
		String basedir = ".";
		// create a file that represents the current directory
		// File f = new File(basedir + File.separator + "chicken.data");
		File f = new File("chicken.data");
		System.out.println("File is " + f.getAbsolutePath());
		try {
			
			FileInputStream fin = new FileInputStream(f);
			while (fin.available() > 0) {
				System.out.println(fin.read());
			}
			
			/* Consider how we'd write the code if we don't use the available() method:
			 * When would the loop stop?
			 * The loop would keep going, waiting for more input.  That could be valid code,
			 * but more often, you probably want to stop looping when you run out of stuff to read,
			 * like from a file.
			 */
			/*
			while( true ) {
				int input = fin.read();
				System.out.println(input);
			}
			*/
			fin.close();
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		File notAFile = new File("/this/is/not/a/file");
		displayInfo(f);
		displayInfo(notAFile);

	}

	/**
	 * Displays info (if it's a file and if it's a directory) about the given file
	 * 
	 * @param myFile the file to display information about
	 */
	private static void displayInfo(File myFile) {
		System.out.println(myFile.getAbsolutePath() + " is a file: "
				+ myFile.isFile());
		System.out.println(myFile.getAbsolutePath() + " is a directory: "
				+ myFile.isDirectory());
	}

}
