首页 > 编程 > Java > 正文

Java 图片复制功能实现过程解析

2019-11-26 08:30:20
字体:
来源:转载
供稿:网友

需求说明

实现思路

见代码注释

代码内容

使用IO复制图片

import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;/** * @auther::9527 * @Description: 第十题 * @program: 多线程 * @create: 2019-08-10 00:26 */public class Tenth {  public static void main(String[] args) {    FileInputStream fis = null;    FileOutputStream fos = null;    try {      //确定输入输出的文件名      fis = new FileInputStream("c:/a.jpg");      fos = new FileOutputStream("c:/b.jpg");      //设定判定器,判定是否读取完毕      int temp = 0;      //开始读取数据,如果没有读完就继续读,按read()方法所说,读完会成为-1,若取值不为-1,则持续读取      while ((temp = fis.read())!=-1){        //将读取到的信息写入文件        fos.write(temp);      }      System.out.println("已将c盘的a.jpg复制为b.jpg");    } catch (FileNotFoundException e) {      e.printStackTrace();    } catch (IOException e) {      e.printStackTrace();    }    try {      //关闭输出流和输入流      fos.close();      fis.close();    } catch (IOException e) {      e.printStackTrace();    }  }}

运行结果

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持武林网。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表