|
Basic Methods zio package context |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object zio.Output
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.
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 |
public Output()
public Output(java.lang.String fileName)
fileName
- the name of the file to be written onMethod Detail |
public final void writeChar(char writeMe)
writeMe
- the char to be writtenpublic final void writeString(java.lang.String writeMe, int size)
writeMe
- the String
to be writtensize
- the size of the output String
public final void writeLine()
Flushes the output buffer.
public final void writeLine(java.lang.String line)
Flushes the output buffer.
line
- the string to be written as a linepublic final void writeInt(int writeMe)
int
.
writeMe
- The int to be converted to String form and written.public final void writeDouble(double writeMe)
double
.
writeMe
- The double to be converted to String form and written.public final void writeInt(int writeMe, int size)
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.
writeMe
- the int
to be writtensize
- the number of characters actually outputpublic final void writeDouble(double writeMe, int fractionalDigits, int size)
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.
writeMe
- the double to be converted to String form and writtenfractionalDigits
- number of fractional digits desiredsize
- the number of characters actually writtenpublic final void close()
Input
or Output
object.
|
author context |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |