StringBuffer sb = new StringBuffer();
sb.append(file.getParent()).append("\\").append(fileName)
.append(endName);
System.out.println(sb.toString());
try {
//读取小文件的输入流
InputStream in = new FileInputStream(file);
//写入大文件的输出流
File file2 = new File(sb.toString());
OutputStream out = new FileOutputStream(file2,true);
int len = -1;
byte[] bytes = new byte[10*1024*1024];
while((len = in.read(bytes))!=-1) {
out.write(bytes, 0, len);
}
out.close();
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println("文件合并完成!");
}
写之前觉得挺复杂,写完之后觉得也就那样,大家也练练手呗。