Java File 文件读取
2022/8/9 1:22:48
本文主要是介绍Java File 文件读取,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
点击查看代码
/** * 文件读取 (单文件读取和多文件读取 ) */ public class FileRead { public static void main(String[] args) throws Exception { multiByteRead(); } //单字节读取 public static void singleByteRead() throws Exception { //读取该文件 File file = new File("D:\\fileTest\\zip\\2022-07-18_20-10-52.jpg"); FileInputStream fileInputStream = new FileInputStream(file); FileOutputStream fileOutputStream = new FileOutputStream("D:\\fileTest\\zip\\hjj.jpg"); int index = 0; while ((index = fileInputStream.read()) != -1) { fileOutputStream.write(index); } fileInputStream.close(); fileOutputStream.close(); } //多字节读取 public static void multiByteRead() throws Exception { //读取该文件 File file = new File("D:\\fileTest\\zip\\2022-07-18_20-10-52.jpg"); FileInputStream fileInputStream = new FileInputStream(file); FileOutputStream fileOutputStream = new FileOutputStream("D:\\fileTest\\zip\\hjj1.jpg"); int index = 0; byte[] bytes = new byte[1024]; while ((index = fileInputStream.read(bytes)) != -1) { fileOutputStream.write(bytes, 0, index); } fileInputStream.close(); fileOutputStream.close(); } }
这篇关于Java File 文件读取的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-20测试人员都是画画大神,让我看看谁还不会用代码图?
- 2024-05-20年薪百万的程序员都在用的摸鱼方式……
- 2024-05-19永别了,微服务架构!
- 2024-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了