// 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
  
/* TextSave.java
 Writes out some text data to be read by the companion program,
TextRead.java, as presented in the article. Both can easily be
modified to be more general text file handlers.

-MAG 15Apr2011
*/

import java.io.*;

public class TextSave{

    public static void main(String[] arg) throws Exception {
        // Create some data to write.
        int x=1, y=2, z=3;
        String name = "Galormadron", race = "elf";
        boolean hyperactive = true;

        // Set up the FileWriter with our file name.
        FileWriter saveFile = new FileWriter("TextSave.txt");

        // Write the data to the file.
        saveFile.write("\n");
        saveFile.write(x + "\n");
        saveFile.write(y + "\n");
        saveFile.write(z + "\n");
        saveFile.write(name + "\n");
        saveFile.write(race + "\n");
        saveFile.write(Boolean.toString(hyperactive) + "\n");
        saveFile.write("\n");

        // All done, close the FileWriter.
        saveFile.close();

    } //main()
} // TextSave
