csv文件内容整合
package file;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class DealWithPhone {
public static void main(String[] args) {
test();
}
public static void test() {
String path="F:\\content1.CSV";
File file=new File(path);
File leaderFile = new File("F:\\content2.csv");
ArrayList<String> list1 = new ArrayList<String>();
list1.add("1893");
ArrayList<String> list2 = new ArrayList<String>();
ArrayList<String> leaderList = new ArrayList<String>();
try {
InputStreamReader leaderReader = new InputStreamReader(new FileInputStream(leaderFile), "gb2312");
BufferedReader brl = new BufferedReader(leaderReader);
String leaderLine = null;
System.out.println("===>文件开始分割!");
int j = 0;
int k =0;
int m =0;
int o =0;
int q =0;
while ((leaderLine = brl.readLine()) != null) {
leaderLine = leaderLine.replace("\"", "");
leaderList.add(leaderLine);
}
brl.close();
InputStreamReader reader = new InputStreamReader(new FileInputStream(file), "gb2312");
BufferedReader br = new BufferedReader(reader);
String line = null;
System.out.println("===>文件开始分割!");
boolean fal = false;
while ((line = br.readLine()) != null) {
j = j+1;
line = line.replace("\"", "");
for (int i = 0; i < leaderList.size(); i++) {
if(line.equals(leaderList.get(i))){
fal=true;
k=k+1;
break;
}
fal = false;
}
if(fal){
m= m+1;
continue;
}
String sub=line.substring(0, 3);
if(sub.equals("189")) {
o=o+1;
list1.add(line.replaceAll(" ", ""));
}else {
q= q+1;
list2.add(line.replaceAll(" ", ""));
}
}
System.out.println("===》文件过滤完毕");
reader.close();
System.out.println(list1.size());
System.out.println(list2.size());
System.out.println("总量:"+j);
System.out.println("判断次数"+k);
System.out.println("过滤次数"+m);
System.out.println("领导电话数:"+leaderList.size());
System.out.println("189条数"+o);
System.out.println("非189条数"+q);
list1.addAll(0,leaderList);
list2.addAll(0,list1);
list2.add("1893");
System.out.println("总条数"+list2.size());
writeFileContext(list2,"F:\\工作空间\\短厅交接\\群发短信操作流程\\全网文件\\20200618_GONGYI_002.CSV");
System.out.println("===》文件分割完毕");
} catch (Exception e) {
e.printStackTrace();
}
}
public static void writeFileContext(List<String> strings, String path) throws Exception {
File file = new File(path);
if (!file.isFile()) {
file.createNewFile();
}
BufferedWriter writer = new BufferedWriter(new FileWriter(path));
for (String l : strings) {
writer.write(l + "\r\n");
}
writer.close();
}
}