title: Merge huge files without loading whole file into memory?
body: <p>I want to merge huge files containing strings into one file and tried to use nio2. I do not want to load the whole file into memory, so I tried it with BufferedReader:</p>
  
  <pre><code>public void mergeFiles(filesToBeMerged) throws IOException{
  
  Path mergedFile = Paths.get("mergedFile");
  Files.createFile(mergedFile);
  
  List&lt;Path&gt; _filesToBeMerged = filesToBeMerged;
  
  try (BufferedWriter writer = Files.newBufferedWriter(mergedFile,StandardOpenOption.APPEND)) {
          for (Path file : _filesToBeMerged) {
  // this does not work as write()-method does not accept a BufferedReader
              writer.append(Files.newBufferedReader(file));
          }
      } catch (IOException e) {
          System.err.println(e);
      }
  
  }
  </code></pre>
  
  <p>I tried it with this, this works, hower, the format of the strings (e.g. new lines, etc is not copied to the merged file):</p>
  
  <pre><code>...
  try (BufferedWriter writer = Files.newBufferedWriter(mergedFile,StandardOpenOption.APPEND)) {
          for (Path file : _filesToBeMerged) {
  //              writer.write(Files.newBufferedReader(file));
              String line = null;
  
  
  BufferedReader reader = Files.newBufferedReader(file);
              while ((line = reader.readLine()) != null) {
                      writer.append(line);
                      writer.append(System.lineSeparator());
               }
  reader.close();
          }
      } catch (IOException e) {
          System.err.println(e);
      }
  ...
  </code></pre>
  
  <p>How can I merge huge Files with NIO2 without loading the whole file into memory? </p>