Java PrintWriter class

Introduction

PrintWriter is a character-oriented version of PrintStream.

PrintWriter has several constructors.

PrintWriter(OutputStream outputStream)  
PrintWriter(OutputStream outputStream, boolean autoFlushingOn)  
PrintWriter(Writer outputStream)  
PrintWriter(Writer outputStream, boolean autoFlushingOn) 
PrintWriter(File outputFile) throws FileNotFoundException  
PrintWriter(File outputFile, String charSet) throws FileNotFoundException, 
                                                    UnsupportedEncodingException  
PrintWriter(String outputFileName) throws FileNotFoundException  
PrintWriter(String outputFileName, String charSet)throws FileNotFoundException, 
                                                    UnsupportedEncodingException 

PrintWriter supports the print() and println() methods for all types.

PrintWriter supports the printf() method.

Here is how printf() is declared in PrintWriter:

PrintWriter printf(String fmtString , Object ... args)  
PrintWriter printf(Locale loc, String fmtString , Object ...args) 

The format() method is also supported. It has these general forms:

PrintWriter format(String fmtString , Object ... args)  
PrintWriter format(Locale loc, String fmtString , Object ... args) 

It works exactly like printf(). 



PreviousNext

Related