Code example for PrintWriter

Methods: close, println, write

0
public final class PrintWriterExample1 { 
 
  public static void main(String[] args) { 
    try { 
      FileOutputStream out = new FileOutputStream("foo.txt"); 
      PrintWriter p = new PrintWriter(out); 
      p.close(); 
      p.println("foo!"); 
      p.write(42); 
 
    } catch (Exception e) { 
      e.printStackTrace(); 
    } 
  } 
}