|
All 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, command windows, sockets,
character arrays, Strings, and File
objects.
Use constructor with file name for file output and without file name for System.out.
Quick Usage:
// 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 Flushing the output buffer is not automatic. It happens only with
these methods: Error behavior can be changed by subclassing the Consider using 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.
writeLine, flush,
and close
.
Zio
class.
File
class in conjunction with this
class; that way offers greater flexibility over the direct use of file names.
Constructor Summary | |
Output()
Creates an Output object capable of writing to the command window. |
|
Output(java.io.File file)
Creates an Output object from any a File object. |
|
Output(java.io.OutputStream stream)
Creates an Ouput object from any OutputStream object. |
|
Output(java.lang.String fileName)
Creates an Output object capable of writing to the named file. |
|
Output(java.io.Writer writer)
Creates an Output object from any writer object. |
Method Summary | |
static void |
appendNextOpenFile()
Makes the next file opening constructor create an object that will append to an existing file. |
void |
close()
Tells operating system your program is finished writing. |
void |
flush()
Flush the output buffer without bothering with writeLine . |
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)
Writes a String. |
void |
writeString(java.lang.String writeMe,
int size)
Writes a String within a specified number
of columns. |
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 onpublic Output(java.io.File file)
public Output(java.io.Writer writer)
public Output(java.io.OutputStream stream)
stream
- any OutputStream objectMethod Detail |
public final void writeChar(char writeMe)
writeMe
- the char to be writtenpublic final void writeString(java.lang.String writeMe)
writeMe
- the String to be writtenpublic final void writeString(java.lang.String writeMe, int size)
String
within a specified number
of columns. The string will be truncated or padded
with blanks as necessary.
size
parameter may be negative, in which
case a string which does not require all -size
columnns
will be right justified within its allotted size.
Normally a string is left justified within its allotted
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)
size
parameter may be negative, in which
case a number which does not require all -size
columnns
will be left justified within its allotted size.
Normally the number is right justified within its allotted
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)
size
parameter may be negative, in which
case a number which does not require all -size
columns
will be left justified within its allotted size.
Normally the number is right justified within its allotted
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.
public static final void appendNextOpenFile()
new Output(String fileName)
or
new Output(File file)
.
public final void flush()
writeLine
.
|
author context |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |