com.skylit.io
Class EasyWriter

java.lang.Object
  extended bycom.skylit.io.EasyWriter

public class EasyWriter
extends java.lang.Object

EasyWriter provides simple methods for opening and * writing to text files. All exceptions are handled * inside the class and are hidden from the user. * *

* Example: * ======= * * EasyWriter outFile = new EasyWriter("anyname.txt"); * if (outFile.bad()) * { * System.err.println("Can't create anyname.txt\n"); * System.exit(1); * } * outFile.print("2 + 2 = "); * outFile.println(4); * outFile.println(); // an extra blank line * outFile.close(); // optional * * @author Gary Litvin * @version 1.1


Field Summary
protected static int CLOSEERROR
           
protected  int myErrorFlags
           
protected  java.lang.String myFileName
           
protected  java.io.PrintWriter myOutFile
           
protected static int OPENERROR
           
protected static int WRITEERROR
           
 
Constructor Summary
EasyWriter(java.lang.String fileName)
          Constructor.
EasyWriter(java.lang.String fileName, java.lang.String mode)
          Constructor.
 
Method Summary
 boolean bad()
          Checks the status of the file * @return true if en error occurred opening or writing to the file, * false otherwise
 void close()
          Closes the file
 void print(char ch)
          Writes one character to the file * @param ch character to be written
 void print(double x)
          Writes a double to the file * @param x number to be written
 void print(int k)
          Writes an integer to the file * @param k number to be written
 void print(java.lang.String s)
          Writes a string to the file * @param s string to be written
 void println()
          Writes a newline character to the file
 void println(char ch)
          Writes one character and newline to the file * @param ch character to be written
 void println(double x)
          Writes a double and newline to the file * @param x number to be written
 void println(int k)
          Writes an integer and newline to the file * @param k number to be written
 void println(java.lang.String s)
          Writes a string and newline to the file * @param s string to be written
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myFileName

protected java.lang.String myFileName

myOutFile

protected java.io.PrintWriter myOutFile

myErrorFlags

protected int myErrorFlags

OPENERROR

protected static final int OPENERROR
See Also:
Constant Field Values

CLOSEERROR

protected static final int CLOSEERROR
See Also:
Constant Field Values

WRITEERROR

protected static final int WRITEERROR
See Also:
Constant Field Values
Constructor Detail

EasyWriter

public EasyWriter(java.lang.String fileName)
Constructor. Creates a new file (or truncates an existing file) * @param fileName the name of the file to be created


EasyWriter

public EasyWriter(java.lang.String fileName,
                  java.lang.String mode)
Constructor. Creates a new file. If the file exists * can append to it. * @param fileName the name of the file to be created * @param mode if equals to "app" opens in append mode

Method Detail

close

public void close()
Closes the file


bad

public boolean bad()
Checks the status of the file * @return true if en error occurred opening or writing to the file, * false otherwise


print

public void print(char ch)
Writes one character to the file * @param ch character to be written


print

public void print(int k)
Writes an integer to the file * @param k number to be written


print

public void print(double x)
Writes a double to the file * @param x number to be written


print

public void print(java.lang.String s)
Writes a string to the file * @param s string to be written


println

public void println()
Writes a newline character to the file


println

public void println(char ch)
Writes one character and newline to the file * @param ch character to be written


println

public void println(int k)
Writes an integer and newline to the file * @param k number to be written


println

public void println(double x)
Writes a double and newline to the file * @param x number to be written


println

public void println(java.lang.String s)
Writes a string and newline to the file * @param s string to be written