- 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();
- }
- }
复制代码 |
|