// From A Beginning Programmer's Guide to Java
// at http://beginwithjava.blogspot.com/
 
// From the article 'Java File Save and File Load: Text'
// at http://beginwithjava.blogspot.com/2011/05/java-file-save-and-file-load-text.html
 
/* TextRead.java
 Reads some text data out of a file created by the companion program,
TextSave.java. This program specifically reads the data as that program
writes it, expecting the information in the same order and format.
-MAG 15Apr2011
*/

import java.io.*;

public class TextRead{

    public static void main(String[] arg) throws Exception {
        int x, y, z;
        String name = "", race = "";
        boolean hyperactive;

        BufferedReader saveFile = new BufferedReader(new FileReader("TextSave.txt"));

        // Throw away the blank line at the top.
        saveFile.readLine(); 
        // Get the integer value from the String.
        x = Integer.parseInt(saveFile.readLine()); 
        y = Integer.parseInt(saveFile.readLine());
        z = Integer.parseInt(saveFile.readLine());
        name = saveFile.readLine();
        race = saveFile.readLine();
        hyperactive = Boolean.parseBoolean(saveFile.readLine());
        // Not needed, but read blank line at the bottom.
        saveFile.readLine(); 

        saveFile.close();

        // Print out the values.
        System.out.println("x=" + x + " y=" + y + " z=" + z + "\n");
        System.out.println("name: " + name + " race: " + race + "\n");
        if (hyperactive) System.out.println("Oh, yeah. He's hyperactive all right.");
        else System.out.println("What a mellow dude.");
        System.out.println();

    } //main()
} // TextRead
