1,示例代码

    

package com.dsczs.io;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * 读文件和写文件操作 还可以进行图片的复制操作 带缓存流
 * @author Administrator
 *
 */
public class Demo06 {

    public static void main(String[] args){
        InputStream in = null;
        OutputStream out = null;
        try {
            File file = new File("C:/Users/Administrator/Desktop/1/1.png");
            in = new BufferedInputStream(new FileInputStream(file));
            out = new BufferedOutputStream(new FileOutputStream(new File("C:/Users/Administrator/Desktop/1/10.png")));
            byte[] b = new byte[1024];
            int len = 0;
            while(-1 != (len = in.read(b))){
                out.write(b, 0, len);
                out.flush();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(in != null){
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(out != null){
                try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

}