首页 > 其他 > 详细

IO流

时间:2021-07-02 01:14:23      阅读:27      评论:0      收藏:0      [点我收藏+]

1.字节流

1.1  InputStream

1.1.1 FileInputStream

(1) read()方法

技术分享图片

 

 

 注:

  1、此方法是从输入流中读取一个数据的字节,即每调用一次read方法,从FileInputStream中读取一个字节

  2、返回下一个数据字节,如果已达到文件末尾,返回-1。

技术分享图片

       3、如果没有输入可用,则此方法将阻塞。Scannner sc = new Scanner(System.in);其中System.in就是InputStream

 1 package IO.InputStreamDemo;
 2 
 3 import java.io.FileInputStream;
 4 
 5 
 6 public class FileInputStreamDemo {
 7 
 8     public static void main(String[] args){
 9         String path="C:/Users/hp/Desktop/IO_Test/InputStreamTest/one.txt";
10         FileInputStream f=null;
11         try{
12 
13             f=new FileInputStream(path);
14             int r;
15             while((r=f.read())!=-1){
16                 System.out.print((char)r);
17             }
18 
19         }catch(Exception e){
20             e.printStackTrace();
21         }finally{
22             try {
23                 //关闭
24                 f.close();
25             }catch (Exception e){
26                 e.printStackTrace();
27             }
28         }
29 
30     }
31 }

IO流

原文:https://www.cnblogs.com/Leeyoung888/p/14959802.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!