黑马程序员技术交流社区
标题:
IO复制文件3种方式
[打印本页]
作者:
虎鹏
时间:
2015-5-17 00:18
标题:
IO复制文件3种方式
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class FileReaderWriterDemo {
public static void main(String[] args) throws IOException {
//普通类
/*InputStreamReader isr = new InputStreamReader(new FileInputStream("EnDemo.java"));
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("copy2.java"));
int ch = -1;
while((ch = isr.read()) != -1){
osw.write(ch);
osw.flush();
}
isr.close();
osw.close();*/
//便捷类
/*FileReader fr = new FileReader("EnDemo.java");
FileWriter fw = new FileWriter("copy3.java");
int ch = -1;
while((ch = fr.read()) != -1){
fw.write(ch);
fw.flush();
}
fr.close();
fw.close();*/
//FileReader fr = new FileReader("EnDemo.java");
//FileWriter fw = new FileWriter("copy3.java");
InputStreamReader isr = new InputStreamReader(new FileInputStream("EnDemo.java"));
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("copy4.java"));
char[] chs = new char[1024];
int len = -1;
while((len = isr.read(chs)) != -1){
osw.write(chs,0,len);
osw.flush();
}
isr.close();
osw.close();
}
}
复制代码
作者:
赵旗
时间:
2015-5-17 00:44
要是能注释下就好了
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2