Basic Methods
zio package

context

zio
Class Output


java.lang.Object

  extended byzio.Output


public class Output
extends java.lang.Object

Provides for text output to files and command windows.

Use constructor with file name for file output and without file name for System.out.

Simple Examples:

 // This example outputs an int, a char, a double, and a String on the
 // next line of the command window.
    Output outc = new Output();  
    outc.writeInt(2);
    outc.writeChar(' ');
    outc.writeDouble(2.2);
    outc.writeString(" -- that's all folks!");
    outc.writeEndOfLine();
 // next example copies a file, line by line from "infile.txt" to 
 // "outfile.txt" using the Input class with the Output class
     Input in = new Input("infile.txt");
     Output out = new Output("outfile.txt");
     for(;;) {
         String line = in.readLine();
         if( in.eof() ) break;
         out.writeLine(line);
     }
     in.close(); out.close();
 

Of the write... methods, only the writeLine method is guaranteed to have finished writing when execution moves on to something else. This may be a significant fact for you if your program terminates abnormally and you are trying to figure out what managed to finish before your program got into trouble.

Version:
Jul 22, 2005
Author:
copyright 2005 by J Adrian Zimmer
Licensed under the Open Software License version 2.1

Constructor Summary
Output()
          Creates an Output object capable of writing to the command window.
Output(java.lang.String fileName)
          Creates an Output object capable of writing to the named file.
 
Method Summary
 void close()
          Tells operating system your program is finished writing.
 void writeChar(char writeMe)
          Writes a character
 void writeDouble(double writeMe)
          Writes a double.
 void writeDouble(double writeMe, int fractionalDigits, int size)
          Writes a double in decimal form within a specified number of columns and using a specified number of digits to the right of the decimal point.
 void writeInt(int writeMe)
          Writes an int.
 void writeInt(int writeMe, int size)
          Writes an int as a decimal number within a specified number of columns.
 void writeLine()
          Writes the character code(s) that signal the end of a line.
 void writeLine(java.lang.String line)
          Writes a String and then writes the character code(s) that signals the end of a line.
 void writeString(java.lang.String writeMe, int size)
          Writes a String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Output


public Output()
Creates an Output object capable of writing to the command window.


Output


public Output(java.lang.String fileName)
Creates an Output object capable of writing to the named file. If file already exists, it will be cleared of content first.

Parameters:
fileName - the name of the file to be written on
Method Detail

writeChar


public final void writeChar(char writeMe)
Writes a character

Parameters:
writeMe - the char to be written

writeString


public final void writeString(java.lang.String writeMe,
                              int size)
Writes a String. A "\n" within the String will cause a new line of output to be begun.

Parameters:
writeMe - the String to be written
size - the size of the output String

writeLine


public final void writeLine()
Writes the character code(s) that signal the end of a line.

Flushes the output buffer.


writeLine


public final void writeLine(java.lang.String line)
Writes a String and then writes the character code(s) that signals the end of a line.

Flushes the output buffer.

Parameters:
line - the string to be written as a line

writeInt


public final void writeInt(int writeMe)
Writes an int.

Parameters:
writeMe - The int to be converted to String form and written.

writeDouble


public final void writeDouble(double writeMe)
Writes a double.

Parameters:
writeMe - The double to be converted to String form and written.

writeInt


public final void writeInt(int writeMe,
                           int size)
Writes an int as a decimal number within a specified number of columns.

The size parameter must allow for at least two columns. If the number does not fit into its allotted space, it will be replaced with two exclamation marks.

Parameters:
writeMe - the int to be written
size - the number of characters actually output

writeDouble


public final void writeDouble(double writeMe,
                              int fractionalDigits,
                              int size)
Writes a double in decimal form within a specified number of columns and using a specified number of digits to the right of the decimal point.

The size parameter must allow for at least two columns. If the number does not fit into its allotted space, it will be replaced with two exclamation marks.

Parameters:
writeMe - the double to be converted to String form and written
fractionalDigits - number of fractional digits desired
size - the number of characters actually written

close


public final void close()
Tells operating system your program is finished writing. Always close files when you are done with them. Files can be reopened with by instantiating another Input or Output object.


author
context