java版
package com.example.demo;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
public class Test2 {
public static void main(String[] args) throws IOException {
Runnable run1 = new MyRunnnmable1();
Runnable run2 = new MyRunnnmable2();
Runnable run3 = new MyRunnnmable3();
Runnable run4 = new MyRunnnmable4();
Thread thread1 = new Thread(run1);
Thread thread2 = new Thread(run2);
Thread thread3 = new Thread(run3);
Thread thread4 = new Thread(run4);
thread1.start();
thread2.start();
thread3.start();
thread4.start();
}
public static void compare(String path, String name,String result) throws IOException {
path = "C:/Users/xietong/Desktop/111";
File outFiles = new File(path + File.separator + result);
OutputStreamWriter write = new OutputStreamWriter(new FileOutputStream(outFiles));
BufferedWriter writer = new BufferedWriter(write);
int i = 0;
File file = new File("C:/Users/xietong/Desktop/111/pidcf.txt");
FileInputStream fisR = new FileInputStream(file);
InputStreamReader isr = new InputStreamReader(fisR, "UTF-8");
BufferedReader br = new BufferedReader(isr);
String line = br.readLine();
while (line != null) {
i++;
File p = new File(path + File.separator + name);
FileInputStream fis = new FileInputStream(p);
InputStreamReader is = new InputStreamReader(fis, "UTF-8");
BufferedReader b = new BufferedReader(is);
System.out.println(line + " " + p.getName() + " " + i + " 当前线程:" + Thread.currentThread());
String content = b.readLine();
while (content != null) {
if (content != null && content.contains(line)) {
writer.write(content);
writer.newLine();
System.out.println("co");
}
content = b.readLine();
}
line = br.readLine();
fis.close();
is.close();
b.close();
}
writer.flush();
fisR.close();
isr.close();
br.close();
// }
write.close();
writer.close();
}
private static String getLine(BufferedReader b) {
String str = null;
try {
str = b.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
class MyRunnnmable1 implements Runnable {
@Override
public void run() {
try {
Test2.compare(null, "al.txt", "汇总1.txt");
} catch (IOException e) {
e.printStackTrace();
}
}
}
class MyRunnnmable2 implements Runnable {
@Override
public void run() {
try {
Test2.compare(null, "cmpay.txt", "汇总2.txt");
} catch (IOException e) {
e.printStackTrace();
}
}
}
class MyRunnnmable3 implements Runnable {
@Override
public void run() {
try {
Test2.compare(null, "wx.txt", "汇总3.txt");
} catch (IOException e) {
e.printStackTrace();
}
}
}
class MyRunnnmable4 implements Runnable {
@Override
public void run() {
try {
Test2.compare(null, "un.txt", "汇总4.txt");
} catch (IOException e) {
e.printStackTrace();
}
}
}