利用文件输入输出流实现图片的复制

涉及到我的输入输出流FileInputStream, FileOutputStream,BufferedInputStream,BufferedOutputStream
后两个是前两个的装饰模式
这里使用了args,使用方法我会附加在后面

import java.io.*;
import java.util.Arrays;

/**
 * @author: Ren
 * @date: 2020-07-30  16:48
 */
public class Copy {
    public static void main(String[] args) throws IOException {
        System.out.println(args[0]);
        System.out.println(args[1]);
//定义路径
        String path = Strongjoin.pathjion(System.getProperty("user.home"), "Desktop", args[0]);
        String path1 = Strongjoin.pathjion(System.getProperty("user.home"), "Desktop", args[1]);
        System.out.println(path);
        //这里是检查路径的
        byte[] buf = new byte[512];
        //以磁盘的一个扇区为单位
        InputStream in = new BufferedInputStream(new FileInputStream(path));
        BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(path1));
        int count =0;
        while((count =in.read(buf))>0) {
            out.write(buf,0,count);
        }
        out.flush();
        in.close();
        out.close();





    }
}


``
args添加属性的前提是java文件编译通过,产生了class文件
点开run窗口
![run/Edit Canfigurations...](https://img-blog.csdnimg.cn/20200730203443828.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDI4MTkyMg==,size_16,color_FFFFFF,t_70)
![1.jpg为被复制文件,2.jpg为复制出来的文件](https://img-blog.csdnimg.cn/20200730203619157.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDI4MTkyMg==,size_16,color_FFFFFF,t_70)

猜你喜欢

转载自blog.csdn.net/weixin_44281922/article/details/107700022