Java Path File List nio mergeFiles(List files, Path mergedFile)

Here you can find the source of mergeFiles(List files, Path mergedFile)

Description

merge Files

License

LGPL

Declaration

public static void mergeFiles(List<Path> files, Path mergedFile) throws IOException 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.io.IOException;
import java.nio.channels.FileChannel;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;

import java.util.List;

public class Main {
    public static void mergeFiles(List<Path> files, Path mergedFile) throws IOException {
        try (FileChannel out = FileChannel.open(mergedFile, StandardOpenOption.APPEND, StandardOpenOption.WRITE)) {
            for (Path path : files) {
                try (FileChannel in = FileChannel.open(path, StandardOpenOption.READ)) {
                    for (long p = 0, l = in.size(); p < l;)
                        p += in.transferTo(p, l - p, out);
                }//from  w ww .jav a2s.  c  o  m
            }
        } catch (IOException e) {
            throw e;
        }
    }
}

Related

  1. listFoldersInFolder2(String path)
  2. listOfWords(String filePath)
  3. listSteps(Path scenarioDirectory)
  4. loadDataFilesList(String prefix, Path bwcIndicesPath)
  5. loadTrainingData(Path path, List input, List output, int outputCount)
  6. mergeInto(List parts, OutputStream out)
  7. pathContainsAny(List strings)
  8. recursiveListFiles(Path file)
  9. recusivelyCollectFileListing(ArrayList rc, Path base, Path directory)