文件的拷贝

文件的拷贝:

方法一:

package com.xuzhiwen.io1;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileCopy {
    public static void main(String[] args) throws IOException {
        FileInputStream in = new FileInputStream("test.txt");
        FileOutputStream out = new FileOutputStream("copytest.txt");
        int len;
        while((len = in.read()) != -1){
            out.write(len);
        }
        in.close();
        out.close();
    }
}

方法二:

package com.xuzhiwen.io1;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileCopy {
    public static void main(String[] args) throws IOException {
        FileInputStream in = new FileInputStream("test.txt");
        FileOutputStream out = new FileOutputStream("copytest.txt");
        int len;
        byte b[] = new byte[1024];
        while((len = in.read(b)) != -1){
            out.write(b,0,len);
        }
        in.close();
        out.close();
    }
}

结果如下:

 

posted @ 2017-08-14 16:27  beibidewomen  阅读(140)  评论(0编辑  收藏  举报