Java I/O流

Java I/O流

input/output流向不同判断为 输入流、输出流 :

1.数据流到我程序的流叫输入流。
2.数据流从我程序流出的流叫输出流。

按照数据的类型分为 字节流、字符流 :

字符流(16bit 文本文件.txt)
字节流 (8bit 非文本文件,图片,视频)

inputstream 字节输入流
outputstream 字节输出流

reader 字符输入流
wirter 字符输出流

按照角色分为 节点流 处理流 :

体系结构

inputstream > FileInputStream 节点流
outputstream > FileOutputStream 节点流
reader > FileReader 节点流
wirter > FileWirter 节点流

代码实现输入流

public void test3() throws IOException {
       FileInputStream fileInputStream = null;
       try {
           fileInputStream = new FileInputStream("D:/hello.txt");
           byte[] b = new byte[3];
           int count = 0;
           while ((count = fileInputStream.read(b)) != -1) {
               System.out.print(new String(b, 0, count));
           }
       } catch (FileNotFoundException e) {
           throw new RuntimeException(e);
       } catch (IOException e) {
           throw new RuntimeException(e);
       } finally {
           fileInputStream.close();
       }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值