虽然程序可以正确的讲读取到的信息输出到文本文件 但是报错:java.io.IOException: Stream closed
不知道是什么原因 菜鸟请各位帮忙看一下
代码如下:
package test;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class Test implements Runnable{
String lineString;
public Test(String line){
this.lineString = line;
}
static FileWriter writer;
static FileReader reader;
public static void main(String[] args) throws IOException {
try {
reader = new FileReader("/Users/tcredit-0002/Desktop/car.txt");
Scanner scanner = new Scanner(reader);
String lineString;
writer = new FileWriter("/Users/tcredit-0002/Desktop/hebei.txt");
// TODO Auto-generated method stub
ExecutorService pool = Executors.newFixedThreadPool(3);
while(scanner.hasNext()){
lineString = scanner.nextLine();
pool.execute(new Test(lineString));
}
scanner.close();
writer.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void run() {
try {
writeResult(lineString);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static synchronized void writeResult(String lineString) throws InterruptedException{
try {
writer.write(lineString+"\r\n");
writer.flush();
System.out.println(lineString);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}