JAVA中的IO流

来源:百度知道 编辑:UC知道 时间:2024/05/25 13:16:18
提取a.txt中的内容输入到b.txt中的代码应该怎么写,请哪位大侠给出具体的代码谢谢。

import java.io.*;

public class TestFileWriter {
public static void main(String[] args) {
FileReader fr = null;
FileWriter fw = null;
int b = 0;
char[] cbuf = new char[18];
try {
fr = new FileReader("E:\\java\\io\\a.txt");
fw = new FileWriter("E:\\java\\io\\b.txt");
while ((b=fr.read(cbuf,0,18))!=-1) {
fw.write(cbuf,0,18);
}
}
catch(FileNotFoundException e) {

e.printStackTrace();
}
catch(IOException e) {
e.printStackTrace();
}
finally {
try {
fr.close();
fw.close();
} catch(IOException e) {

e.printStackTrace();
}
}
}
}

import java.io.*;
public class Test