import java.io.*; class WriteFile { public static void main(String args[]) { FileOutputStream foStream; PrintStream pStream; try { foStream = new FileOutputStream("somefile.txt"); pStream = new PrintStream( foStream ); pStream.println("This is written to a file"); pStream.close(); } catch (Exception e) { System.err.println ("Error writing to file " e); } } }