尝试这样,从单独的文件一个一个地读取,写入一个文件。下面的简单代码供您理解。试试这个,我希望它对你有用。您可以改进此代码。
InputStream in1 = new FileInputStream("sourceLocation1");
InputStream in2 = new FileInputStream("sourceLocation2");
InputStream in3 = new FileInputStream("sourceLocation3");
InputStream in4 = new FileInputStream("sourceLocation4");
OutputStream out = new FileOutputStream("targetLocation");
// Copy the bits from instream to outstream
byte[] buf = new byte[1024];
int len;
while ((len = in1.read(buf)) > 0) {
out.write(buf, 0, len);
}
while ((len = in2.read(buf)) > 0) {
out.write(buf, 0, len);
}
while ((len = in3.read(buf)) > 0) {
out.write(buf, 0, len);
}
while ((len = in4.read(buf)) > 0) {
out.write(buf, 0, len);
}
in1.close();
in2.close();
in3.close();
in4.close();
out.close();