title: Split large file into chunks
body: <p>I have a method which accept file and size of chunks and return list of chunked files. But the main problem that my line in file could be broken, for example in main file I have next lines:</p>
  
  <pre><code>|1|aaa|bbb|ccc|
  |2|ggg|ddd|eee|
  </code></pre>
  
  <p>After split I could have in one file:</p>
  
  <pre><code>|1|aaa|bbb
  </code></pre>
  
  <p>In another file:</p>
  
  <pre><code>|ccc|2|
  |ggg|ddd|eee|
  </code></pre>
  
  <p>Here is the code:</p>
  
  <pre><code>public static List&lt;File&gt; splitFile(File file, int sizeOfFileInMB) throws    IOException {
    int counter = 1;
    List&lt;File&gt; files = new ArrayList&lt;&gt;();
  
    int sizeOfChunk = 1024 * 1024 * sizeOfFileInMB;
    byte[] buffer = new byte[sizeOfChunk];
  
    try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file))) {
      String name = file.getName();
  
      int tmp = 0;
      while ((tmp = bis.read(buffer)) &gt; 0) {
          File newFile = new File(file.getParent(), name + "."
                  + String.format("%03d", counter++));
          try (FileOutputStream out = new FileOutputStream(newFile)) {
              out.write(buffer, 0, tmp);
          }
  
          files.add(newFile);
      }
    }
  
    return files;
  }
  </code></pre>
  
  <p>Should I use <strong>RandomAccessFile</strong> class for above purposes (main file is really big - more then 5 Gb)?</p>