拷贝图片

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

public class Demo3 {

    /**
     * @param args
     * @throws IOException 
     */
    public static void main(String[] args) throws IOException {
        
        copyImage();
        
    }
    public static void copyImage() throws IOException {
        // 找到目标文件
        File file = new File("C:\\cc\\kk\\1.jpg");    
        // 建立通道
        FileInputStream inputStream = new FileInputStream(file);
File file1
= new File("C:\\cc\\tc.jpg"); FileOutputStream outputStream = new FileOutputStream(file1);
//创建一个缓冲区 byte[] b = new byte[1024 * 6]; //循环遍历文件内容,没有就返回-1 while (inputStream.read(b) != -1) {
//写入数据 outputStream.write(b); }
//关闭流      关闭流的原则:先开后关,后开先关 outputStream.close();
inputStream.close(); } }

 

posted @ 2016-12-05 17:16  彬之华666  阅读(171)  评论(0编辑  收藏  举报