当前位置:网站首页>IO流简介
IO流简介
2022-07-27 14:44:00 【w͏l͏j͏】
IO流
数据的无结构化传递
File
既可以代表目录,也可以代表文件
mkdir(),mkdirs(),createNewFile() boolean
is开头的是判断文件属性
exists判断文件或者文件夹是否存在(boolean)
delete删除文件夹的前提是文件夹是一个空文件夹
length(),getName() 见名知义
getParentFile()
File[] listFiles() ; 获取文件夹内部的问价和文件夹
IO流分类
- 字符流(字节流+编码表)
- 输入流 Reader
- FileReader
- 类似FileInputStream的使用
- FileReader
- 输出流 Writer
- FileWriter
- write()到缓冲区,记得flush()
- fw.close()的时候也会把数据刷新到文件中去。
- 参数可以是字符,字符数组,字符串
- FileWriter
- 输入流 Reader
- 字节流
- 输入流 InputStream
- FileInputStream
- 读取文件流
- 读取数据原理:java程序–>JVM–>OS–>OS读取数据的方法–>读取文件
- 使用步骤:
- 创建FileInputStream对象,构造方法中绑定要读取的数据源
- 使用FileInputStream对象中的方法read,读取文件
- 释放资源
- int read() 从输入流中读取数据的下一个字节。 返回 0 到 255 范围内的 int 字节值。 如果因为已经到达流末尾而没有可用的字节, 则返回值 -1。
- int read(byte[] b) 从此输入流中将最多 b.length (最好是1024的整数倍) 个字节的数据读入一个 byte 数组中。
- void close()
- FileInputStream
- 输出流 OutputStream(写数据)
- FileOutputStream(String name,boolean append) 第二个参数表示是否续写
- write()
- FileOutputStream(String name,boolean append) 第二个参数表示是否续写
- 输入流 InputStream
- 使用原则
- 对于文本文件(.txt,.java,.c,.cpp),使用字符流处理。
- 对于非文本文件(.jpg,.mp3,.mp4,.avi,.doc,.ppt,…),使用字节流处理。
- 使用字节流FileInputStream处理文本文件,可能出现乱码
- 编码表
- ASCII
- GBK
- Unicode
- 乱码:编码解码不一致
- 解决:重新编码再解码,或者指定解码方式
- 高效缓冲流
- 解决磁盘与内存速度不匹配的问题
- Buffer开头
- BufferedInputStream
- BufferedOutputStream
- BufferedReader
- BufferedWriter
- 特有的方法
- readLine() 不包括换行符 条件:!=null
- newLine()写入一个换行符
边栏推荐
- [sword finger offer] interview question 52: the first common node of two linked lists - stack, hash table, double pointer
- It can carry 100 people! Musk releases the strongest "starship" in history! Go to Mars as early as next year!
- [regular expression] single character matching
- 台积电6纳米制程将于明年一季度进入试产
- [sword finger offer] interview question 39: numbers that appear more than half of the time in the array
- 云管平台中租户以及多租户概念简单说明
- C语言程序设计(第三版)
- Axure 安装图标字体元件库
- Live broadcast software development, customized pop-up effect of tools
- Easy to understand, distinguish between ++i and I++
猜你喜欢

微信小程序个人号开通流量主

Openwrt增加对 sd card 支持

webRTC中的coturn服务安装

Ncnn reasoning framework installation; Onnx to ncnn

keil 采用 makefile 实现编译

Openwrt adds RTC (mcp7940 I2C bus) drive details

C language: string function and memory function

Pychart imports the existing local installation package

SQL multi table query

QT (VI) value and string conversion
随机推荐
一款功能强大的Web漏洞扫描和验证工具(Vulmap)
多行文本溢出打点
Busybox login: can't execute'/bin/bash': no such file or directory solution
时间序列——使用tsfresh进行分类任务
To meet risc-v challenges? ARM CPU introduces custom instruction function!
Nacos
企业运维安全就用行云管家堡垒机!
Under the ban, the Countermeasures of security giants Haikang and Dahua!
突发!海康/大华/商汤/旷视/依图/科大讯飞等28家中国实体被美列入黑名单
Stock account opening commission discount, stock trading account opening which securities company is good, is online account opening safe
Mapreduce实例(二):求平均值
借5G东风,联发科欲再战高端市场?
接连取消安富利/文晔/世平代理权,TI到底打的什么算盘?
Flask connects to existing tables in MySQL database
C language: custom type
C language realizes the conversion between byte stream and hexadecimal string
leetcode25题:K 个一组翻转链表——链表困难题目详解
C language: data storage
Clickhouse 20.x distributed table testing and chproxy deployment (II)
Pychart imports the existing local installation package