fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.io.PrintStream;
  4. import java.io.IOException;
  5. import java.io.File;
  6.  
  7. import java.util.Random;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. try
  15. { PrintStream writer = new PrintStream( new File("randInts.txt"));
  16. Random r = new Random();
  17. final int LIMIT = 100;
  18.  
  19. for(int i = 0; i < LIMIT; i++)
  20. { writer.println( r.nextInt() );
  21. }
  22. writer.close();
  23. }
  24. catch(IOException e)
  25. { System.out.println("An error occured while trying to write to the file");
  26. }
  27. }
  28. }
Success #stdin #stdout 0.1s 54764KB
stdin
Standard input is empty
stdout
An error occured while trying to write to the file