加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

Java 测试: 图片复制

发布时间:2020-12-15 05:24:32 所属栏目:Java 来源:网络整理
导读:|--需求说明 ? ? ? |--实现思路 见代码注释 ? |--代码内容 1 import java.io.FileInputStream; 2 import java.io.FileNotFoundException; 3 import java.io.FileOutputStream; 4 import java.io.IOException; 5 6 /** 7 * @auther::9527 8 * @Description:

|--需求说明

?

?

?

|--实现思路

见代码注释

?

|--代码内容

 1 import java.io.FileInputStream;
 2 import java.io.FileNotFoundException;
 3 import java.io.FileOutputStream;
 4 import java.io.IOException;
 5 
 6 /**
 7  * @auther::9527
 8  * @Description: 第十题
 9  * @program: 多线程
10  * @create: 2019-08-10 00:26
11  */
12 public class Tenth {
13     public static void main(String[] args) {
14         FileInputStream fis = null;
15         FileOutputStream fos = null;
16 
17         try {
18             //确定输入输出的文件名
19             fis = new FileInputStream("c:/a.jpg");
20             fos = new FileOutputStream("c:/b.jpg");
21             //设定判定器,判定是否读取完毕
22             int temp = 0;
23             //开始读取数据,如果没有读完就继续读,按read()方法所说,读完会成为-1,若取值不为-1,则持续读取
24             while ((temp = fis.read())!=-1){
25                 //将读取到的信息写入文件
26                 fos.write(temp);
27             }
28             System.out.println("已将c盘的a.jpg复制为b.jpg");
29         } catch (FileNotFoundException e) {
30             e.printStackTrace();
31         } catch (IOException e) {
32             e.printStackTrace();
33         }
34         try {
35             //关闭输出流和输入流
36             fos.close();
37             fis.close();
38         } catch (IOException e) {
39             e.printStackTrace();
40         }
41     }
42 }
使用IO复制图片

?

?

?

|--运行结果

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读