title: Java: Read large file by 'n' records at a time
body: <p>I have an input text file having 5k records. I want to read in 1k records, pass as parameter to SQL query IN clause (which is limited to 1k values) and then get the next 1k records from text file and repeat. How can I do this in java. Below is sample code i have so far:</p>
  
  <pre><code>FileInputStream fis = null;
      BufferedReader reader = null;
  
      try {
          fis = new FileInputStream("values.txt");
          reader = new BufferedReader(new InputStreamReader(fis))
          int i,counter=0;
          do{
          String line;
          ArrayList values = new ArrayList();
          for(i=0;i&lt;1000;i++){
              line = reader.readLine();
              values.append(line);
              if(line ==null)
                  break;
          }
          counter = i;
          String sql = ....;
          //db connection
          }while(counter&lt;6000);
          conn.close;
       }
  </code></pre>