java InputStream用来复制图片

    xiaoxiao2021-12-14  21

    package 练习12号; import java.io.*; public class ImageCopy { public static void main(String[] args) throws IOException{ FileOutputStream fw=null; FileInputStream fr=null; try{ fw=new FileOutputStream("zxn.jpg"); fr=new FileInputStream("Desert.jpg"); byte[] buf=new byte[1024]; int len=0; while((len=fr.read(buf))!=-1){ //将byte数据读到最多buf长度的buf数组中 fw.write(buf,0,len); //将buf中 从0-len长度的数据写到文件中 } } catch(IOException e){ System.out.println("输入错误"); } finally{ try{ if(fr!=null){ fr.close(); } } catch(IOException e){ System.out.println("关闭失败"); } } } }
    转载请注明原文地址: https://ju.6miu.com/read-971717.html

    最新回复(0)