public class Demo_02 {
public static void main(String[] args) throws IOException {
FileInputStream fis = new FileInputStream("D:\\练习\\feige.exe");
String path = "D:\\练习\\temp";
byte[] bytes = new byte[1024*1024];
int len = -1;
int name = 0;
while ((len = fis.read(bytes)) != -1){
FileOutputStream fos = new FileOutputStream(new File(path,++name+".temp.txt"));
fos.write(bytes,0,len);
fos.close();
}
fis.close();
File file = new File(path);
mergeFile(file);
}
public static void mergeFile(File file) throws IOException {
File[] files = file.listFiles();
FileOutputStream fos = new FileOutputStream("D:\\练习\\test\\feige1.exe");
byte[] bytes = new byte[8192];
int len;
for (File f:files){
FileInputStream fis = new FileInputStream(f);
while ((len = fis.read(bytes)) != -1){
fos.write(bytes,0,len);
}
fis.close();
}
fos.close();
}
}