最近学习了异常和I/O流
package fourweek;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
public class IO {
public static void
main(String[] args) throws Exception{ //创建字节流
InputStream fis = new FileInputStream("a.txt"); OutputStream fos = new FileOutputStream("b.txt");
//创建桥转换流--字符流
InputStreamReader is=new InputStreamReader(fis,"GBK"); OutputStreamWriter os = new OutputStreamWriter(fos);
//创建字符过滤流
BufferedReader reader = new BufferedReader(is);
BufferedWriter writer = new BufferedWriter(os); //操作流对象
while(true) {
String s=reader.readLine(); if(s==null) break; writer.write(s); writer.newLine();
}
//关闭流对象
reader.close();
writer.close();
}
}