forked from TimSongCoder/LearnJavaForAndroid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMerge.java
More file actions
55 lines (54 loc) · 1.27 KB
/
Copy pathMerge.java
File metadata and controls
55 lines (54 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.File;
import java.io.FilenameFilter;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
public class Merge{
public static void main(String[] args){
File dir = new File(".");
File[] files = dir.listFiles(new FilenameFilter(){
@Override
public boolean accept(File dir, String name){
return name.contains("_part_");
}
});
if(files.length < 1){
System.err.println("No valid part files.");
return;
}
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try{
String temp = files[0].getName();
File mergeFile = new File("Merge_" + temp.substring(0, temp.indexOf("_")));
bos = new BufferedOutputStream(new FileOutputStream(mergeFile));
for(File file: files){
bis = new BufferedInputStream(new FileInputStream(file));
int read;
while((read = bis.read())!=-1){
bos.write(read);
}
bis.close();
}
}catch(IOException ioe){
ioe.printStackTrace();
}finally{
if(bis!=null){
try{
bis.close();
}catch(IOException ioe){
ioe.printStackTrace();
}
}
if(bos!=null){
try{
bos.close();
}catch(IOException ioe){
ioe.printStackTrace();
}
}
}
}
}