* 字符流的练习之复制Java文件
*
* 数据源 : "PhoneTest.java"
* 目的地 : "copy.java"
*
* InputStreamReader : 字符输入流
* OutputStreamWriter: 字符输出流
public class Demo3 {
public static void main(String[] args) throws IOException {
// 创建字符输入流对象
InputStreamReader isr = new InputStreamReader(new FileInputStream("PhoneTest.java"));
// 创建字符输出流对象
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("copy.java"));
// 一次读写一个字符
// int ch;
// while ((ch = isr.read()) != -1) {
// osw.write(ch);
// }
// 一次读写一个字符数组
char[] chs = new char[1024];
int len;
while ((len = isr.read(chs)) != -1) {
osw.write(chs, 0, len);
}
// 释放资源
isr.close();
osw.close();
}
}