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); } } } #### open my $fh, ">", "somefile.txt" or die "Can't open file: $!"; print $fh "This is written to a file\n" or die "Can't print to file: $!";