|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.io.OutputStream
java.io.FilterOutputStream
java.io.PrintStream
public class PrintStream
This class prints Java primitive values and object to a stream as
text. None of the methods in this class throw an exception. However,
errors can be detected by calling the checkError() method.
Additionally, this stream can be designated as "autoflush" when
created so that any writes are automatically flushed to the underlying
output sink when the current line is terminated.
This class converts char's into byte's using the system default encoding.
| Field Summary |
|---|
| Fields inherited from class java.io.FilterOutputStream |
|---|
out |
| Constructor Summary | |
|---|---|
PrintStream(File file)
This method initializes a new PrintStream object to write
to the specified output File. |
|
PrintStream(File file,
String encoding)
This method initializes a new PrintStream object to write
to the specified output File. |
|
PrintStream(OutputStream out)
This method intializes a new PrintStream object to write
to the specified output sink. |
|
PrintStream(OutputStream out,
boolean auto_flush)
This method intializes a new PrintStream object to write
to the specified output sink. |
|
PrintStream(OutputStream out,
boolean auto_flush,
String encoding)
This method intializes a new PrintStream object to write
to the specified output sink. |
|
PrintStream(String fileName)
This method initializes a new PrintStream object to write
to the specified output File. |
|
PrintStream(String fileName,
String encoding)
This method initializes a new PrintStream object to write
to the specified output File. |
|
| Method Summary | |
|---|---|
PrintStream |
append(char c)
Appends the Unicode character, c, to this Appendable
object. |
PrintStream |
append(CharSequence cs)
Appends the specified sequence of Unicode characters to this Appendable object. |
PrintStream |
append(CharSequence cs,
int start,
int end)
Appends the specified subsequence of Unicode characters to this Appendable object, starting and ending at the specified
positions within the sequence. |
boolean |
checkError()
This method checks to see if an error has occurred on this stream. |
void |
close()
This method closes this stream and all underlying streams. |
void |
flush()
This method flushes any buffered bytes to the underlying stream and then flushes that stream as well. |
PrintStream |
format(Locale locale,
String format,
Object... args)
|
PrintStream |
format(String format,
Object... args)
|
void |
print(boolean bool)
This methods prints a boolean value to the stream. |
void |
print(char ch)
This method prints a char to the stream. |
void |
print(char[] charArray)
This method prints an array of characters to the stream. |
void |
print(double dnum)
This method prints a double to the stream. |
void |
print(float fnum)
This method prints a float to the stream. |
void |
print(int inum)
This method prints an integer to the stream. |
void |
print(long lnum)
This method prints a long to the stream. |
void |
print(Object obj)
This method prints an Object to the stream. |
void |
print(String str)
This method prints a String to the stream. |
PrintStream |
printf(Locale locale,
String format,
Object... args)
|
PrintStream |
printf(String format,
Object... args)
|
void |
println()
This method prints a line separator sequence to the stream. |
void |
println(boolean bool)
This methods prints a boolean value to the stream. |
void |
println(char ch)
This method prints a char to the stream. |
void |
println(char[] charArray)
This method prints an array of characters to the stream. |
void |
println(double dnum)
This method prints a double to the stream. |
void |
println(float fnum)
This method prints a float to the stream. |
void |
println(int inum)
This method prints an integer to the stream. |
void |
println(long lnum)
This method prints a long to the stream. |
void |
println(Object obj)
This method prints an Object to the stream. |
void |
println(String str)
This method prints a String to the stream. |
protected void |
setError()
This method can be called by subclasses to indicate that an error has occurred and should be reported by checkError. |
void |
write(byte[] buffer,
int offset,
int len)
This method writes len bytes from the specified array
starting at index offset into the array. |
void |
write(int oneByte)
This method writes a byte of data to the stream. |
| Methods inherited from class java.io.FilterOutputStream |
|---|
write |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public PrintStream(OutputStream out)
PrintStream object to write
to the specified output sink.
out - The OutputStream to write to.
public PrintStream(OutputStream out,
boolean auto_flush)
PrintStream object to write
to the specified output sink. This constructor also allows "auto-flush"
functionality to be specified where the stream will be flushed after
every print or println call, when the
write methods with array arguments are called, or when a
single new-line character is written.
out - The OutputStream to write to.auto_flush - true to flush the stream after every
line, false otherwise
public PrintStream(File file)
throws FileNotFoundException
PrintStream object to write
to the specified output File. Doesn't autoflush.
file - The File to write to.
FileNotFoundException - if an error occurs while opening the file.
public PrintStream(File file,
String encoding)
throws FileNotFoundException,
UnsupportedEncodingException
PrintStream object to write
to the specified output File. Doesn't autoflush.
file - The File to write to.encoding - The name of the character encoding to use for this
object.
FileNotFoundException - If an error occurs while opening the file.
UnsupportedEncodingException - If the charset specified by
encoding is invalid.
public PrintStream(String fileName)
throws FileNotFoundException
PrintStream object to write
to the specified output File. Doesn't autoflush.
fileName - The name of the File to write to.
FileNotFoundException - if an error occurs while opening the file,
public PrintStream(String fileName,
String encoding)
throws FileNotFoundException,
UnsupportedEncodingException
PrintStream object to write
to the specified output File. Doesn't autoflush.
fileName - The name of the File to write to.encoding - The name of the character encoding to use for this
object.
FileNotFoundException - if an error occurs while opening the file.
UnsupportedEncodingException - If the charset specified by
encoding is invalid.
public PrintStream(OutputStream out,
boolean auto_flush,
String encoding)
throws UnsupportedEncodingException
PrintStream object to write
to the specified output sink. This constructor also allows "auto-flush"
functionality to be specified where the stream will be flushed after
every print or println call, when the
write methods with array arguments are called, or when a
single new-line character is written.
out - The OutputStream to write to.auto_flush - true to flush the stream after every
line, false otherwiseencoding - The name of the character encoding to use for this
object.
UnsupportedEncodingException| Method Detail |
|---|
public boolean checkError()
true forever for this stream. Before checking for an
error condition, this method flushes the stream.
true if an error has occurred,
false otherwiseprotected void setError()
checkError.
public void close()
close in interface Closeableclose in class FilterOutputStreampublic void flush()
flush in interface Flushableflush in class FilterOutputStreampublic void print(boolean bool)
true
values are printed as "true" and false values are printed
as "false".
bool - The boolean value to printpublic void print(int inum)
String.valueOf() method.
inum - The int value to be printedpublic void print(long lnum)
String.valueOf() method.
lnum - The long value to be printedpublic void print(float fnum)
String.valueOf() method.
fnum - The float value to be printedpublic void print(double dnum)
String.valueOf() method.
dnum - The double value to be printedpublic void print(Object obj)
Object to the stream. The actual
value printed is determined by calling the String.valueOf()
method.
obj - The Object to print.public void print(String str)
String to the stream. The actual
value printed depends on the system default encoding.
str - The String to print.public void print(char ch)
ch - The char value to be printedpublic void print(char[] charArray)
charArray - The array of characters to print.public void println()
public void println(boolean bool)
true
values are printed as "true" and false values are printed
as "false".
This method prints a line termination sequence after printing the value.
bool - The boolean value to printpublic void println(int inum)
String.valueOf() method.
This method prints a line termination sequence after printing the value.
inum - The int value to be printedpublic void println(long lnum)
String.valueOf() method.
This method prints a line termination sequence after printing the value.
lnum - The long value to be printedpublic void println(float fnum)
String.valueOf() method.
This method prints a line termination sequence after printing the value.
fnum - The float value to be printedpublic void println(double dnum)
String.valueOf() method.
This method prints a line termination sequence after printing the value.
dnum - The double value to be printedpublic void println(Object obj)
Object to the stream. The actual
value printed is determined by calling the String.valueOf()
method.
This method prints a line termination sequence after printing the value.
obj - The Object to print.public void println(String str)
String to the stream. The actual
value printed depends on the system default encoding.
This method prints a line termination sequence after printing the value.
str - The String to print.public void println(char ch)
This method prints a line termination sequence after printing the value.
ch - The char value to be printedpublic void println(char[] charArray)
This method prints a line termination sequence after printing the value.
charArray - The array of characters to print.public void write(int oneByte)
write in class FilterOutputStreamoneByte - The byte to be written
public void write(byte[] buffer,
int offset,
int len)
len bytes from the specified array
starting at index offset into the array.
write in class FilterOutputStreambuffer - The array of bytes to writeoffset - The index into the array to start writing fromlen - The number of bytes to writepublic PrintStream append(char c)
AppendableAppendable
object.
append in interface Appendablec - the character to append.
public PrintStream append(CharSequence cs)
AppendableAppendable object. The entire sequence may not
be appended, if constrained by the underlying implementation.
For example, a buffer may reach its size limit before the entire
sequence is appended.
append in interface Appendablecs - the character sequence to append. If seq is null,
then the string "null" (the string representation of null)
is appended.
public PrintStream append(CharSequence cs,
int start,
int end)
AppendableAppendable object, starting and ending at the specified
positions within the sequence. The entire sequence may not
be appended, if constrained by the underlying implementation.
For example, a buffer may reach its size limit before the entire
sequence is appended. The behaviour of this method matches the
behaviour of append(seq.subSequence(start,end)) when
the sequence is not null.
append in interface Appendablecs - the character sequence to append. If seq is null,
then the string "null" (the string representation of null)
is appended.start - the index of the first Unicode character to use from
the sequence.end - the index of the last Unicode character to use from the
sequence.
public PrintStream printf(String format,
Object... args)
public PrintStream printf(Locale locale,
String format,
Object... args)
public PrintStream format(String format,
Object... args)
public PrintStream format(Locale locale,
String format,
Object... args)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||