码迷,mamicode.com
首页 > 编程语言 > 详细

java IO流拷贝图片

时间:2015-05-24 20:15:16      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:

图片属于字节流,使用InputStream和OutputStream。

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

public class CopyImage {

    public static void main(String[] args) throws IOException {
        
        File inFile = new File("F:\\1.jpg");
        File outFile = new File("D:\\1.jpg");
        
        FileInputStream in = new FileInputStream(inFile);
        FileOutputStream out = new FileOutputStream(outFile);
        byte[] buf = new byte[1024];
        int length = 0;
        
        //边读边写
        while ((length = in.read(buf)) != -1) {
            out.write(buf, 0, length);
        }
        
        out.close();
        in.close();
    }

}

 

java IO流拷贝图片

标签:

原文地址:http://www.cnblogs.com/syliuchang/p/4526343.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!