当前位置: 首页 > article >正文

Java进阶文件输入输出实操(图片拷贝)

Java进阶文件输入输出实操(图片拷贝)
  • 把某个目录下的全部图片,全部拷贝到另外一个目录

    package test;

    import domee.chapter6_7.B;

    import java.io.*;

    public class Ex10_10 {
    public static void main(String[] args) throws IOException {
    String dir = “C:\Users\123\Desktop\test”;
    creatFile(dir);
    File file = new File(dir+“\img”);
    File[] files = file.listFiles();
    for (File file1 : files){
    String name = file1.getName();
    System.out.println(name);
    copy(file.getAbsolutePath()+“”+name,dir+“\copy”+name);
    }

    }
    
    
    
    public static void creatFile(String dir){
        File file = new File(dir+"\copy");
        file.mkdir();
    }
    
    
    public static void copy(String from,String to)throws IOException {
    
    
        InputStream inputStream = new FileInputStream(from);
        OutputStream outputStream = new FileOutputStream(to);
        BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream);
        byte[] bytes = new byte[inputStream.available()];
        int size ;
        while ( (size = inputStream.read(bytes))!= -1){
            bufferedOutputStream.write(bytes,0,size);
        }
        bufferedInputStream.close();
        bufferedOutputStream.close();
    
    
    
    }
    

    }


http://www.kler.cn/a/534091.html

相关文章:

  • 大语言模型轻量化:知识蒸馏的范式迁移与工程实践
  • 音频录制一般在什么情况下会选择保存为PCM?什么情况会选择保存为WAV?
  • spring基础总结
  • xxl-job 自定义告警短信发送
  • 知识蒸馏教程 Knowledge Distillation Tutorial
  • UI线程用到COM只能选单线程模型
  • 安装mindspore_rl踩坑
  • 【深度学习】Java DL4J基于 RNN 构建智能停车管理模型
  • 华为OD最新机试真题-狼羊过河-Java-OD统一考试(E卷)
  • 大语言模型极速部署:Ollama 、 One-API、OpenWebUi 完美搭建教程
  • 大语言模型的「幻觉」(Hallucination)是指模型在生成内容时
  • 玩转goroutine:Golang中对goroutine的应用
  • js的 encodeURI() encodeURIComponent() decodeURI() decodeURIComponent() 笔记250205
  • 解决python写入csv时如000111样式的字符串前面的0被忽略掉的问题
  • DeepSeek-R1:开源机器人智能控制系统的革命性突破
  • Linux中安装rabbitMQ
  • 【含文档+PPT+源码】Python爬虫人口老龄化大数据分析平台的设计与实现
  • .net framework 4.5 的项目,用Mono 部署在linux
  • 【算法篇】选择排序
  • Mysql:数据库
  • docker单机运行环境的zabbix升级实战(从6.2.6升级到7.2.3)
  • Centos 8 离线升级openssh 9.9
  • Linux下线程间同步实现方式详解
  • ZooKeeper单节点详细部署流程
  • 【Kubernetes Pod间通信-第3篇】Kubernetes中Pod与ClusterIP服务之间的通信
  • OSPF基础(1)