FindFileTest.java
2.39 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package com.thinkgem.jeesite.tools;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import com.google.common.collect.Lists;
import com.thinkgem.jeesite.common.utils.JsonUtil;
public class FindFileTest {
public static void main(String[] args) {
String namefile = "G:\\names.txt";
List<String> names = getNameList(namefile);
String srcpath = "G:\\updatas\\";
String distpath = "G:\\dicts\\";
Integer existsNum = 0;
Integer qsNum = 0;
for (String name : names) {
String filename = "Biz"+name+".xml";
Boolean exists = exists(srcpath, filename);
if(exists) {
copyFile(srcpath, distpath, filename);
existsNum++;
}else {
qsNum++;
}
}
System.out.println("总数:"+names.size()+",存在:"+existsNum+",缺失:"+qsNum);
}
private static void copyFile( String srcpath,String distpath,String name) {
File srcFile = new File(srcpath+name);
File distFile = new File(distpath+name);
InputStream in = null;
OutputStream out = null;
try {
in = new FileInputStream(srcFile);
out = new FileOutputStream(distFile);
byte[] buffer = new byte[10240];
int len;
while ((len = in.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
System.out.println("文件"+name+"复制完成");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
in.close();
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
private static Boolean exists( String srcpath, String name) {
File srcFile = new File(srcpath+name);
Boolean exist = srcFile.exists();
System.out.println("文件"+(srcpath+name)+(exist?"存在":"缺失"));
return exist;
}
private static List<String> getNameList(String filepath){
List list = Lists.newArrayList();
try {
FileReader fr = new FileReader(filepath);
BufferedReader bf = new BufferedReader(fr);
String str;
// 按行读取字符串
while ((str = bf.readLine()) != null) {
list.add(str);
}
bf.close();
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
return list;
}
}