publicPrintWriter(OutputStream out)
Equivalent to PrintWriter(newOutputStreamWriter(out),
false).
publicPrintWriter(File file)throws FileNotFoundException
Equivalent to PrintWriter(newOutputStreamWriter(fos)) ,
where fos is a FileOutputStream created with the given file.
publicPrintWriter(File file, String enc)tHRows
FileNotFoundException, UnsupportedEncodingException
Equivalent to PrintWriter(newOutputStreamWriter(fos,
enc)), where fos is a FileOutputStream created with the given file.
publicPrintWriter(String filename)throws FileNotFoundException
Equivalent to PrintWriter(newOutputStreamWriter(fos)) ,
where fos is a FileOutputStream created with the given file name.
publicPrintWriter(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 methods are provided for formatted outputsee
"Formatter" on page 624 for details:
public PrintWriterformat(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 PrintWriterformat(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 methodsprintf 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 checkErrorthis flushes the stream and
checks its error state. Once an error 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().