集册 Java实例教程 复制JPG文件

复制JPG文件

欢马劈雪     最近更新时间:2020-01-02 10:19:05

541
复制JPG文件
/** 来自 时 代 J a v a**/

import java.io.*;


public class CopyJPGFile {

    public static void main(String[] args) {

        try (FileInputStream source = new FileInputStream(new File("files/picture.jpg"));

             FileOutputStream destination = new FileOutputStream(new File("files/my-copied-picture.jpg"))){


            byte[] buffer = new byte[4096];

            while (true){

                int readBytes = source.read(buffer,0,buffer.length);

                if(readBytes <= 0){

                    break;

                } else {

                    destination.write(buffer,0,readBytes);/** 来 自 NowJava.com**/

                }

            }


     
展开阅读全文