Skip to content

Instantly share code, notes, and snippets.

@veryyoung
Last active October 10, 2015 08:40
Show Gist options
  • Select an option

  • Save veryyoung/3b43dbc8c8e7dbfa432f to your computer and use it in GitHub Desktop.

Select an option

Save veryyoung/3b43dbc8c8e7dbfa432f to your computer and use it in GitHub Desktop.
合并文件,可用来制作传说中的图种。运行时把文件路径当做参数传入,最后一个参数为输出文件的路径。
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
public class FileGathering {
public static void main(String[] args) throws IOException {
combineFiles(args);
}
public static void combineFiles(String[] paths) throws IOException {
int pathsSize = paths.length;
if (pathsSize < 2) {
System.err.println("请至少输入两个文件路径");
return;
}
File outputFile = new File(paths[pathsSize - 1]);
if (!outputFile.exists()) {
outputFile.createNewFile();
}
FileChannel outputFileChannel = new FileOutputStream(outputFile).getChannel();
FileChannel inFileChannel;
for (int i = 0; i < pathsSize; i++) {
inFileChannel = new FileInputStream(new File(paths[i])).getChannel();
inFileChannel.transferTo(0, inFileChannel.size(), outputFileChannel);
inFileChannel.close();
}
outputFileChannel.close();
}
}
@lanmodie
Copy link

perfect!

@theopengroup
Copy link

no GUI, no STAR!

@veryyoung
Copy link
Author

write GUI for me! @theopengroup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment