首页 > 其他 > 详细

图片拷贝

时间:2016-12-05 20:03:29      阅读:317      评论:0      收藏:0      [点我收藏+]
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
  
  
public class demo6 {
  
    /**
     * 把一张图片拷贝到指定的位置
     
     */
    public static void main(String[] args) throws IOException {
        //拿到图片的路径
        File file = new File("C:\\Users\\PC-LUO\\Desktop\\新建文件夹\\98.jpg");
        //创建拷贝后的路径
        File file2 = new File("C:\\Users\\PC-LUO\\Desktop\\4.jpg");
          
        image(file, file2);
    }
      
    //拷贝操作
    public static void image(File file , File file2) throws IOException{
          
        //输入流
        FileInputStream inputStream = new FileInputStream(file);
        //输出流
        FileOutputStream outputStream = new FileOutputStream(file2);
          
        //创建缓冲区,大小为1K
        byte[] b = new byte[1024];
          
        //循环遍历文件内容,没有就返回-1
        while (inputStream.read(b) != -1) {
            //把得到的数据写入到指定位置
            outputStream.write(b);  
        }
        //关闭资源
        outputStream.close();
        inputStream.close();
    }
  
}

图片拷贝

原文:http://www.cnblogs.com/zh-0802/p/6134703.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!