JAVA 字符流复制JAVA文件 147


import java.io.*;

public class CopyJavaDemo {
    public static void main(String[] args) throws IOException {
        File file = new File("./src/CopyJavaDemo.java");
        if(file.isFile()){
            //字节流进行操作
            InputStreamReader isr = new InputStreamReader(new FileInputStream(file));
            String Path = "./src/Copy.java";
            OutputStreamWriter osw= new OutputStreamWriter(new FileOutputStream(Path));
            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(); }
else { System.out.println("文件不存在"); } } }