Java Reference
In-Depth Information
public
PrintWriter(String
filename,
String
enc)
tHRows
FileNotFoundException, UnsupportedEncodingException
Equivalent to
PrintWriter(newOutputStreamWriter(fos, enc))
,
where
fos
is a
FileOutputStream
created with the given file
name.
The
Print
streams implement the
Appendable
interface which allows them
to be targets for a
Formatter
. Additionally, the following convenience
for details:
public PrintWriter
format(String format, Object... args)
Acts like
new Formatter(this).format(format,args)
, but a new
Formatter
need not be created for each call. The current
PrintWriter
is returned.
public PrintWriter
format(Locale l, String format, Object... args)
Acts like
new Formatter(this, l).format(format, args)
, but a
new
Formatter
need not be created for each call. The current
PrintWriter
is returned. Locales are described in
Chapter 24
.
There are two
printf
methods that behave exactly the same as the
format
methods
printf
stands for "print formatted" and is an old friend
from the
C
programming language.
One important characteristic of the
Print
streams is that none of the
output methods throw
IOException
. If an error occurs while writing to
the underlying stream the methods simply return normally. You should
check whether an error occurred by invoking the boolean method
check-
Error
this flushes the stream and checks its error state. Once an er-
ror has occurred, there is no way to clear it. If any of the underlying
stream operations result in an
InterruptedIOException
, the error state
is not set, but instead the current thread is re-interrupted using
Thread.currentThread().interrupt()
.