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

FileInputStream

FileInputStream循环读取:

public class Test3 {public static void main(String[] args) throws IOException {FileInputStream fis=new FileInputStream("C:\\Users\\小新\\IdeaProjects\\Test\\src\\text");int b;while ((b=fis.read())!=-1){System.out.print((char) b);}//释放资源fis.close();}
}

文件拷贝基本代码(边读边写):

public class Test3 {public static void main(String[] args) throws IOException {//拷贝的路径FileInputStream fis=new FileInputStream("C:\\Users\\小新\\IdeaProjects\\Test\\src\\text");//拷贝到的路径FileOutputStream fos=new FileOutputStream("C:\\Users\\小新\\IdeaProjects\\Test\\src\\copy");//利用while循环边读边写int b;while ((b= fis.read())!=-1){fos.write(b);}fos.close();fis.close();}
}

如果要拷贝大文件,我们可以利用数组,但是数组也会占用内存,所以,我们经量用合适的数组。

public class Test3 {public static void main(String[] args) throws IOException {//拷贝的路径FileInputStream fis=new FileInputStream("C:\\Users\\小新\\IdeaProjects\\Test\\src\\text");//拷贝到的路径FileOutputStream fos=new FileOutputStream("C:\\Users\\小新\\IdeaProjects\\Test\\src\\copy");//利用while循环边读边写int len;byte[] bytes=new byte[1024*1024*5];while ((len=fis.read(bytes))!=-1){fos.write(bytes,0,len);}//释放资源fos.close();fis.close();}
}

http://www.xdnf.cn/news/4725.html

相关文章:

  • 日语学习-日语知识点小记-构建基础-JLPT-N4阶段(15):何と どういう
  • process-exporter服务安装并启动
  • 【C++游戏引擎开发】第32篇:物理引擎(Bullet)—约束系统
  • ollama+deepseek+openwebui安装
  • OrangePi Zero 3学习笔记(Android篇)2 - 第一个C程序
  • 创建需求跟踪矩阵5大常见步骤(附注意事项)
  • linux - shell脚本编程
  • 解锁 AI 生产力:Google 四大免费工具全面解析20250507
  • vue3+ts的watch全解!
  • 登顶中国:基于 Trae AI与 EdgeOne MCP 的全国各省最高峰攀登攻略博客构建实践
  • 比较入站和出站防火墙规则
  • 使用Apache Spark在Java中进行日志分析
  • 如何快速获取旺店通奇门原始数据至本地
  • 掌握Multi-Agent实践(二):基于AgentScope构建支持@机制的群聊系统,实现定向对话机制
  • LeetCode 热题 100 322. 零钱兑换
  • CATIA高效工作指南——零件建模篇(二)
  • 多边形生成立面点云
  • Python理财应用-- A股指标对比 | AKShare【未完待续】
  • 【视觉基础模型-SAM系列-1】Segment Anything
  • std::atomic<bool>与bool的区别
  • AI Agent四大范式:解锁智能体的进化密码
  • 算法探索:合并区间问题深度解析
  • nRF Connect SDK system off模式介绍
  • FEKO许可使用效率分析
  • 微服务架构详解
  • 掌握Multi-Agent实践(一):使用AgentScope实践入门和Workstation上手指南
  • 快速上手知识图谱开源库pykeen教程指南(一)
  • element-plus中,vue3项目,el-input密码框禁止浏览器自动弹出浏览器历史密码提示框
  • 华清远见陶金华受邀武汉大学讲座: 共话“算力下沉”时代,赋能AloT技术新未来
  • 【大模型面试每日一题】Day 11:参数高效微调方法(如LoRA、Adapter)的核心思想是什么?相比全参数微调有何优缺点?