KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > java > io > PrintWriter

java.io
Class PrintWriter

java.lang.Object
  extended by java.io.Writer
      extended by java.io.PrintWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable
See Also:
Top Examples, Source Code, checkError(), PrintStream

public PrintWriter append(char c)
See Also:
Writer, Appendable
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public PrintWriter append(CharSequence csq)
See Also:
Writer, Appendable
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public PrintWriter append(CharSequence csq,
                          int start,
                          int end)
See Also:
IndexOutOfBoundsException, Writer, Appendable
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean checkError()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void close()
See Also:
checkError(), Writer, Closeable
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[163]Copy a file line by line
By Anonymous on 2004/02/12 21:44:36  Rate
//Copy a file 
 try 
  {      
    String line = null; 
    BufferedReader br = new BufferedReader ( new FileReader ( "oldFileName" )  ) ; 
    PrintWriter pr = new PrintWriter ( new BufferedWriter ( new FileWriter ( "newFileName", false )  )  ) ;       
          
    while  (  ( line = br.readLine (  )  )  != null )   {  
         pr.println ( line ) ; 
     }  
   
    br.close (  ) ;             
    br = null; 
        
    pr.close (  ) ; 
    pr = null;         
        
  }  catch  ( java.io.FileNotFoundException ex )   {  
    System.out.println ( "File '" + args [ 0 ]  + "' does not exist. " ) ;       
  }  catch  ( java.io.IOException ex )   {  
    ex.printStackTrace (  ) ; 
  }  
 


public void flush()
See Also:
checkError(), Writer, Flushable
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public PrintWriter format(String format,
                          Object... args)
See Also:
NullPointerException, Locale.getDefault()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public PrintWriter format(Locale l,
                          String format,
                          Object... args)
See Also:
NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected Writer out
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void print(boolean b)
See Also:
write(int), String.valueOf(boolean)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void print(char c)
See Also:
write(int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void print(char[] s)
See Also:
NullPointerException, write(int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void print(double d)
See Also:
Double.toString(double), write(int), String.valueOf(double)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void print(float f)
See Also:
Float.toString(float), write(int), String.valueOf(float)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void print(int i)
See Also:
Integer.toString(int), write(int), String.valueOf(int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void print(Object obj)
See Also:
Object.toString(), write(int), String.valueOf(Object)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void print(String s)
See Also:
write(int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void print(long l)
See Also:
Long.toString(long), write(int), String.valueOf(long)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public PrintWriter printf(String format,
                          Object... args)
See Also:
NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public PrintWriter printf(Locale l,
                          String format,
                          Object... args)
See Also:
NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void println()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void println(boolean x)
See Also:
println(), print(boolean)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void println(char x)
See Also:
println(), print(char)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void println(char[] x)
See Also:
println(), print(char[])
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void println(double x)
See Also:
println(), print(double)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void println(float x)
See Also:
println(), print(float)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void println(int x)
See Also:
println(), print(int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void println(Object x)
See Also:
println(), print(Object)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void println(String x)
See Also:
println(), print(String)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[290]Simple Servlet
By Anonymous on 2003/06/27 09:57:15  Rate
 
 import javax.servlet.http.*; 
  
  
 public class HelloWorldServlet extends HttpServlet  {  
   public void doGet (  HttpServletRequest req, HttpServletResponse resp  )  
            throws javax.servlet.ServletException, java.io.IOException  {  
     java.io.PrintWriter pw = resp.getWriter (  ) ; 
     String str = req.getParameter (  "str"  ) ; 
  
  
     pw.println (  " < html >  < head >  < title > ServletQueryReply Title < /title >  < /head >  < body > "  ) ; 
  
  
     if  ( str == null )   {  
       pw.println (  " < form method=post action=Query > "  ) ; 
       pw.println (  " < b > Enter text:  < /b > "  ) ; 
       pw.println (  " < input type=text name=str >  < p > "  ) ; 
       pw.println (  " < input type=submit value=\"Go to next page\""  ) ; 
      }  else  {  
       pw.println (  "The previous text was:  < b > " + str + " < /b >  < p > "  ) ; 
       pw.println (  " < a HREF=Query > Return to previous page < /a > "  ) ; 
      }  
  
  
     pw.println (  " < /body >  < /html > "  ) ; 
     pw.close (  ) ; 
    }  
   public void doPost (  HttpServletRequest req, HttpServletResponse resp  )  
            throws javax.servlet.ServletException, java.io.IOException  {  
     doGet (  req, resp  ) ; 
  }   } 


public void println(long x)
See Also:
println(), print(long)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public PrintWriter(File file)
            throws FileNotFoundException
See Also:
checkWrite(file.getPath()), SecurityException, OutputStreamWriter
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public PrintWriter(File file,
                   String csn)
            throws FileNotFoundException,
                   UnsupportedEncodingException
See Also:
checkWrite(file.getPath()), SecurityException, charset, OutputStreamWriter
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public PrintWriter(OutputStream out)
See Also:
OutputStreamWriter.OutputStreamWriter(java.io.OutputStream)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public PrintWriter(OutputStream out,
                   boolean autoFlush)
See Also:
OutputStreamWriter.OutputStreamWriter(java.io.OutputStream)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public PrintWriter(Writer out)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public PrintWriter(Writer out,
                   boolean autoFlush)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public PrintWriter(String fileName)
            throws FileNotFoundException
See Also:
checkWrite(fileName), SecurityException, OutputStreamWriter
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public PrintWriter(String fileName,
                   String csn)
            throws FileNotFoundException,
                   UnsupportedEncodingException
See Also:
checkWrite(fileName), SecurityException, charset, OutputStreamWriter
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected void setError()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void write(char[] buf)
See Also:
Writer
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void write(char[] buf,
                  int off,
                  int len)
See Also:
Writer
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void write(int c)
See Also:
Writer
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void write(String s)
See Also:
Writer
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void write(String s,
                  int off,
                  int len)
See Also:
Writer
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags