文章分类 -  io流

摘要:实例化Properties集合 Properties properties = new Properties(); 往集合中添加数据 properties.setProperty("name", "张三"); properties.setProperty("age", "18"); 遍历Proper 阅读全文
posted @ 2022-12-14 03:28 Amireux-126 阅读(26) 评论(0) 推荐(0) 编辑
摘要:Properties: 属性集合。继承了Hashtable,线程安全。 特点 1、存储属性名和属性值。 2、属性名和属性值都是字符串类型。 3、没有泛型。 4、与流有关。 阅读全文
posted @ 2022-12-14 03:03 Amireux-126 阅读(87) 评论(0) 推荐(0) 编辑
摘要:递归遍历文件夹 public static void main(String[] args) throws Exception { listDir(new File("D:\\stu")); } /** * 递归遍历文件夹下文件夹及文件信息 * * @param dir */ public stat 阅读全文
posted @ 2022-12-14 02:49 Amireux-126 阅读(90) 评论(0) 推荐(0) 编辑
摘要:public interface FileFilter { /** * Tests whether or not the specified abstract pathname should be * included in a pathname list. * * @param pathname 阅读全文
posted @ 2022-12-14 02:31 Amireux-126 阅读(3) 评论(0) 推荐(0) 编辑
摘要:实例化文件夹对象 File dir = new File("D:\\stu\\file"); 创建文件夹 //创建文件夹前先判断当前文件夹是否存在,如果不存在则创建文件夹,存在则不创建 if (!dir.exists()) { //创建单级文件夹,如果stu文件夹不存在,会创建失败 boolean 阅读全文
posted @ 2022-12-14 02:19 Amireux-126 阅读(32) 评论(0) 推荐(0) 编辑
摘要:1、创建File文件对象 //创建File对象,指定文件路径,这里可以使用绝对路径,也可以使用相对路径 File file = new File("D:\\stu\\file.txt"); 2、创建文件 //创建文件 返回值true:代表文件创建成功;false:代表文件创建失败。 boolean 阅读全文
posted @ 2022-12-14 01:36 Amireux-126 阅读(44) 评论(0) 推荐(0) 编辑
摘要:分隔连续多个路径的分隔符 File.pathSeparator:在Unix上为 :(冒号);在windows上为;(分号)。 File.pathSeparatorChar:在Unix上为 :(冒号);在windows上为;(分号)。 文件路径间隔符: File.separator:在Unix上为/( 阅读全文
posted @ 2022-12-14 01:02 Amireux-126 阅读(428) 评论(0) 推荐(0) 编辑
摘要:概念 java File类以抽象的方式代表我们本地磁盘上的文件或者文件夹。该类主要用于文件或文件夹的查找、创建、删除等操作。 File类中的方法 createNewFile:创建一个新文件夹 mkdir():创建一个新目录 delete():删除文件或空目录 exists():判断该文件是否存在 g 阅读全文
posted @ 2022-12-14 00:41 Amireux-126 阅读(3) 评论(0) 推荐(0) 编辑
摘要:特点 1、可将字节流转换为字符流。 2、可设置字符的编码格式。 InputStreamReader(字符转换输入流):将字节流转换为字符流,并指定编码格式。 public static void main(String[] args) throws Exception { //创建文件字节输入流对象 阅读全文
posted @ 2022-12-14 00:29 Amireux-126 阅读(5) 评论(0) 推荐(0) 编辑
摘要:PrintWriter: 1、封装了print()/println()方法,支持写入后换行。 2、支持数据原样打印。 案例 public static void main(String[] args) throws Exception { //创建打印流 PrintWriter printWrite 阅读全文
posted @ 2022-12-13 21:10 Amireux-126 阅读(3) 评论(0) 推荐(0) 编辑
摘要:特点 1、高效读写。 2、支持输入换行符。 3、可一次写一行,读一行。 BufferedReader(字符缓冲输入流) public static void main(String[] args) throws Exception { //定义文件字符输入流,定义输入文件地址 FileReader 阅读全文
posted @ 2022-12-13 20:58 Amireux-126 阅读(13) 评论(0) 推荐(0) 编辑
摘要:public static void main(String[] args) throws Exception { //创建文件字符输入流对象,并指定文件地址 FileReader fileReader = new FileReader("D:\\stu\\a.txt"); //实例化文件字符输出流 阅读全文
posted @ 2022-12-13 20:19 Amireux-126 阅读(15) 评论(0) 推荐(0) 编辑
摘要:FileReader:文件字符输入流。 public static void main(String[] args) throws Exception { //创建文件字符输入流fileReader FileReader fileReader = new FileReader("D:\\stu\\a 阅读全文
posted @ 2022-12-13 20:13 Amireux-126 阅读(14) 评论(0) 推荐(0) 编辑
摘要:Reader:字符输入流。 public abstract class Reader implements Readable, Closeable {}; Writer:字符输出流。 public abstract class Writer implements Appendable, Closea 阅读全文
posted @ 2022-12-13 19:40 Amireux-126 阅读(3) 评论(0) 推荐(0) 编辑
摘要:ASCII编码:用来表示英文,它使用1个字节表示,其中第一位规定为0,其他7位存储数据,一共可以表示128个字符。 拓展ASCII编码:用于表示更多的欧洲文字,用8个位存储数据,一共可以表示256个字符 GBK/GB2312/GB18030:表示汉字。GBK/GB2312表示简体中文,GB18030 阅读全文
posted @ 2022-12-13 04:36 Amireux-126 阅读(22) 评论(0) 推荐(0) 编辑
摘要:对象流的好处: 1、增强了缓冲区功能 2、增强了读写8种基本数据类型和字符串功能:readByte()、writeByte()、readChar()、writeChar()等。 3、增强了读写对象的功能:readObject()、writeObject(Object obj)。 序列化和反序列化: 阅读全文
posted @ 2022-12-13 03:42 Amireux-126 阅读(9) 评论(0) 推荐(0) 编辑
摘要:缓冲流的好处 提高IO效率,减少访问磁盘的次数; 使用说明 数据存储在缓冲区中,通过flush()方法将缓冲区的数据写入文件中。也可以直接使用close()方法,因为close方法里就调用了flush()方法。 1、BufferInputStream(字节输入缓冲流) public static v 阅读全文
posted @ 2022-12-13 03:36 Amireux-126 阅读(20) 评论(0) 推荐(0) 编辑
摘要:public static void main(String[] args) throws Exception { //创建文件输入流对象,定义输入文件地址 FileInputStream fileInputStream = new FileInputStream("D:\\stu/bbb.txt" 阅读全文
posted @ 2022-12-13 02:43 Amireux-126 阅读(7) 评论(0) 推荐(0) 编辑
摘要:什么是缓冲区? 缓冲区是一个固定长的数据存储容器。 缓冲区的好处: 1、一次性加载大量数据到缓冲区,数据读取通过缓冲区来进行,减少了数据磁盘的访问次数。 阅读全文
posted @ 2022-12-13 02:25 Amireux-126 阅读(5) 评论(0) 推荐(0) 编辑
摘要:FileInputStream 单个字节读取: public static void main(String[] args) throws Exception { //创建文件字节流FileInputStream对象,并指定文件路径 FileInputStream fileInputStream = 阅读全文
posted @ 2022-12-13 02:10 Amireux-126 阅读(34) 评论(0) 推荐(0) 编辑