Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 0.50 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.io.*;
  2.  
  3. class WriteATextFile
  4. {
  5.    public static void main (String[] args)
  6.    {
  7.       try
  8.       {
  9.          PrintWriter writer = new PrintWriter("MyFile.txt");
  10.          writer.print("String1 line 1");
  11.          writer.println();
  12.          writer.print("1 2 3 line 2");
  13.          writer.println();
  14.          writer.println();
  15.          writer.print("1 2 3 line 4");
  16.          
  17.          writer.close();
  18.       }
  19.       catch (IOException e)
  20.       {
  21.          e.printStackTrace();
  22.       }
  23.    }
  24. }