package cm.test;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
public class Get_Member_Code {
private HashMap<String, String> map = new HashMap<String, String>();
private Set<String> set = new HashSet<>();
public Get_Member_Code() {
if (init("D:\\cust")) {
System.out.println("success load");
}
}
public static void main(String[] args) {
try {
BufferedReader bf = new BufferedReader(new FileReader("D:\\111.txt"));
BufferedWriter bw = new BufferedWriter(new FileWriter("D:\\result.txt", true));
Get_Member_Code code = new Get_Member_Code();
String name = "";
int count = 0;
while ((name = bf.readLine()) != null) {
String result = "";
if ((result = code.is_contain(name)) != null) {
bw.write(result + "\t");
}
System.out.println(++count + "\t" + name);
}
bw.flush();
bw.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public String is_contain(String name) {
if (set.contains(name)) {
return name + "\t" + map.get(name);
}
return null;
}
public boolean init(String path) {
File root_path = new File(path);
for (File file : root_path.listFiles()) {
String str = "";
BufferedReader br;
try {
br = new BufferedReader(new FileReader(file));
while ((str = br.readLine()) != null) {
map.put(str.split("\t")[1], str.split("\t")[0]);
}
System.out.println(file.getName());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
set = (Set<String>) map.keySet();
return true;
}
}
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
public class Get_Member_Code {
private HashMap<String, String> map = new HashMap<String, String>();
private Set<String> set = new HashSet<>();
public Get_Member_Code() {
if (init("D:\\cust")) {
System.out.println("success load");
}
}
public static void main(String[] args) {
try {
BufferedReader bf = new BufferedReader(new FileReader("D:\\111.txt"));
BufferedWriter bw = new BufferedWriter(new FileWriter("D:\\result.txt", true));
Get_Member_Code code = new Get_Member_Code();
String name = "";
int count = 0;
while ((name = bf.readLine()) != null) {
String result = "";
if ((result = code.is_contain(name)) != null) {
bw.write(result + "\t");
}
System.out.println(++count + "\t" + name);
}
bw.flush();
bw.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public String is_contain(String name) {
if (set.contains(name)) {
return name + "\t" + map.get(name);
}
return null;
}
public boolean init(String path) {
File root_path = new File(path);
for (File file : root_path.listFiles()) {
String str = "";
BufferedReader br;
try {
br = new BufferedReader(new FileReader(file));
while ((str = br.readLine()) != null) {
map.put(str.split("\t")[1], str.split("\t")[0]);
}
System.out.println(file.getName());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
set = (Set<String>) map.keySet();
return true;
}
}