import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
/**
*
* @desc <p>
* 合并多个文件内容
* </p>
* @author ynshun
* @version 1.0
* @date 2013-8-1 下午2:46:54
*/
public class CombinFile {
/**
* 合并文件
*
* @param filePath
* 需要合并的文件路径
* @param newFile
* 合并后形成的新文件
* @throws Exception
*/
@SuppressWarnings("resource")
public void combinFile(String[] filePath, String newFile) throws Exception {
FileOutputStream fOS = new FileOutputStream(new File(newFile));
byte[] buffer = null;
FileInputStream fis = null;
for (int i = 0; i < filePath.length; i++) {
File file = new File(filePath[i]);
fis = new FileInputStream(file);
buffer = new byte[fis.available()];
fis.read(buffer);
fOS.write(buffer);
}
fis.close();
fOS.flush();
}
public static void main(String[] args) throws Exception {
String[] filePath = {"C:\\Users\\nengshun\\Desktop\\新建文本文档.html","C:\\Users\\nengshun\\Desktop\\用户中心连调错误.txt"};
String newFile = "C:\\Users\\nengshun\\Desktop\\新建文本文档.txt";
CombinFile c = new CombinFile();
c.combinFile(filePath, newFile);
}
}