验证中...
Work.java
Raw Copy
import java.io.*;
import java.util.*;
public class Work {
public static void main(String[] args) {
//管道流,输入
PipedInputStream pi=new PipedInputStream();
//管道流,输出
PipedOutputStream po=new PipedOutputStream();
try {
po.connect(pi);//将输入和输出链接
} catch (IOException e) {
e.printStackTrace();
}
Thread a=new Thread(new Read(new BufferedReader(new InputStreamReader(pi))));
Thread b=new Thread(new Write(new BufferedWriter(new OutputStreamWriter(po))));
a.start();
b.start();
}
}
class Read implements Runnable{
BufferedReader re=null;
static ArrayList<String> list=new ArrayList<String>();
public Read(BufferedReader re){
this.re=re;
}
@Override
public void run() {
try {
re=new BufferedReader(new FileReader("D:\\file.txt"));
while(true){
String str=re.readLine();
if(str==null){
break;
}
list.add(str);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
if(re!=null){
try {
re.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
class Write implements Runnable{
BufferedWriter we=null;
public Write(BufferedWriter we){
this.we=we;
}
@Override
public void run() {
try {
we=new BufferedWriter(new FileWriter("E:\\file.txt"));
for(String str:Read.list){
we.write(str);
we.newLine();
we.flush();
}
} catch (IOException e) {
e.printStackTrace();
}finally{
if(we!=null){
try {
we.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}

Comment list( 1 )

冰心易冷 2018-05-12 16:37

你不是人造革,你是真的皮!---胖哥骚气

You need to Sign in for post a comment

Help Search