Advertisement
Guest User

TheChildClass

a guest
Nov 17th, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. package fileiotestapplication;
  2. import java.io.*;
  3. import java.io.IOException;
  4. import java.util.*;
  5.  
  6.  
  7. public class WriterClass {
  8.  
  9. @SuppressWarnings("oracle.jdeveloper.java.insufficient-catch-block")
  10. public WriterClass() {
  11. super();
  12.  
  13. // File f = new File("C:\\Java_Scratch\\someFile.txt");
  14.  
  15.  
  16. int[] content = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,};
  17. String[] friends = {"bob",};
  18.  
  19. File file = new File("/C:/Java_Scratch/someFile.txt");
  20. // if file doesnt exists, then create it
  21.  
  22.  
  23. try {
  24.  
  25. if (!file.exists()) {
  26. file.createNewFile();
  27. }
  28.  
  29.  
  30. //BufferedWriter bw = new BufferedWriter(fw);
  31.  
  32. for (int i = 0 ; i < content.length; i++)
  33. {
  34. //FileWriter fw = new FileWriter(file.getAbsoluteFile(), true);
  35. PrintStream bw = new PrintStream( new FileOutputStream(file, true) );
  36.  
  37. System.out.println("testing " + i);
  38. bw.println( String.valueOf(content[i]) );
  39. bw.close();
  40.  
  41.  
  42. Thread.sleep(2500);
  43. }
  44.  
  45.  
  46. System.out.println("Done");
  47. } catch (IOException ioe) {
  48. // TODO: Add catch code
  49. ioe.printStackTrace();
  50. }
  51. catch (InterruptedException ioe) {
  52. // TODO: Add catch code
  53. ioe.printStackTrace();
  54. }
  55.  
  56.  
  57.  
  58.  
  59.  
  60. //someIS.println(i);
  61. System.out.println("This is OK");
  62.  
  63.  
  64.  
  65. }
  66.  
  67. public static void main(String[] args) {
  68. WriterClass writerClass = new WriterClass();
  69.  
  70.  
  71.  
  72.  
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement