Guest User

BigFileWriter

a guest
Dec 19th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. import java.io.BufferedWriter;
  2. import java.io.FileWriter;
  3. import java.io.IOException;
  4.  
  5. public class BigFileWriter {
  6.  
  7.     public static final int NUM_LINES = 6 * 10000000;
  8.     public static final double MY_DOUBLE = 0.123;
  9.    
  10.     public static void main(String[] args) {
  11.         BufferedWriter out = null;
  12.         try {
  13.             out = new BufferedWriter(new FileWriter("bigFile.txt"));
  14.            
  15.             out.write("" + NUM_LINES);
  16.             out.newLine();
  17.            
  18.             for (int i = 0; i < NUM_LINES; i++) {
  19.                 out.write(i + " " + (i + 1));
  20.                 out.newLine();
  21.             }
  22.            
  23.             for (int i = 0; i < NUM_LINES; i++) {
  24.                 final double doubleValue = MY_DOUBLE + i;
  25.                 final double doubleValue2 = MY_DOUBLE + i + 1;
  26.                 out.write(doubleValue + " " + doubleValue2);
  27.                 out.newLine();
  28.             }
  29.            
  30.         } catch (IOException e) {
  31.             e.printStackTrace();
  32.         }
  33.        
  34.         try {
  35.             out.close();
  36.         } catch (IOException e) {
  37.             e.printStackTrace();
  38.         }
  39.     }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment