首页 > 其他分享 >IO流知识:FilelnputStream单个字节读取文件

IO流知识:FilelnputStream单个字节读取文件

时间:2022-08-19 13:34:15浏览次数:52  
标签:字节 read FilelnputStream System int 转义字符 IO FileInputStream 读取

 1 package IO;
 2 
 3 import java.io.FileInputStream;
 4 import java.io.FileNotFoundException;
 5 import java.io.IOException;
 6 /*
 7 需求:读取"E:\\javaIo\\day01\\javaSe.txt"此路径中的文件数据到内存中;
 8  */
 9 public class Test06 {
10     public static void main(String[] args) throws FileNotFoundException {
11         //1.创建一个输入流FileInputStream
12         FileInputStream f = new FileInputStream("E:\\javaIo\\day01\\javaSe.txt");
13         //2.read()读取磁盘中的数据到内存,从硬盘中每次读取一个字节的数据到内存中
14         try {
15             int read = f.read();
16             System.out.println((char) read);//转义字符,进行强制转换
17             int read1 = f.read();
18             System.out.println((char) read1);//转义字符,进行强制转换
19             int read2 = f.read();
20             System.out.println((char) read2);//转义字符,进行强制转换
21         } catch (IOException e) {
22             e.printStackTrace();
23         }finally {
24             //3.释放资源
25             if (f !=null){
26                 try {
27                     f.close();
28                 } catch (IOException e) {
29                     e.printStackTrace();
30                 }
31             }
32         }
33     }
34 }

 

标签:字节,read,FilelnputStream,System,int,转义字符,IO,FileInputStream,读取
From: https://www.cnblogs.com/nzm-2019/p/16601683.html

相关文章