字节流读取数据注意事项
来源:互联网 发布:网络电视手机在线直播 编辑:程序博客网 时间:2024/06/01 09:02
import java.io.BufferedInputStream;import java.io.FileInputStream;import java.io.IOException;/* * 注意:虽然我们有两种方式可以读取,但是,请注意,这两种方式针对同一个对象在一个代码中只能使用一个。 */public class BufferedInputStreamDemo {public static void main(String[] args) throws IOException {// BufferedInputStream(InputStream in)BufferedInputStream bis = new BufferedInputStream(new FileInputStream("fos3.txt")); //读取数据 int by = 0; while ((by = bis.read()) != -1) { System.out.print((char) by); } System.out.println("---------");byte[] bys = new byte[1024];int len = 0;while ((len = bis.read(bys)) != -1) {System.out.print(new String(bys, 0, len));}// 释放资源bis.close();}}
结果只输出一份数据:
hello0
hello1
hello2
hello3
hello4
hello5
hello6
hello7
hello8
hello9
hello0
hello1
hello2
hello3
hello4
hello5
hello6
hello7
hello8
hello9
---------
0 0
- 字节流读取数据注意事项
- 用java流读取字节文件的注意事项
- 加密数据之 -- 字节流的读取
- Java使用字节流读取数据
- 关于.net数据读取注意事项
- IO流_FileInputStream读取数据一次一个字节数组
- 字节流读取文件
- 文件读取字节流
- 复制文件读取(字节数据) ,写字节数据
- 从硬件里读取字节数据
- Java字节流数据逐行读取(readLine),处理以Tab分隔符划分的数据
- java缓冲字节流的复制数据,数据以数组读取、写入,效率更高
- C#读取二进制字节流
- C#读取二进制字节流
- 模拟字节读取流缓冲区
- Java IO流字节读取
- 字节流_FileInputStream类读取
- 字节输入输出流的代码注意事项
- mapreduce
- TabLayout
- 《剑指offer》-两个链表的第一个公共结点
- 15.2 asyncio--异步I/O事件库
- 欢迎使用CSDN-markdown编辑器
- 字节流读取数据注意事项
- 程序员常用工具大全(转载+原创)
- [Cloud Computing]Mechanisms: Automatically Defined Perimeter Controller
- 微信 支付异步回调 获取参数值
- 使用Eclipse里的Tomcat经常内存溢出的解决方法
- 匈牙利算法模板
- 【iReport+JasperReport】3.在Java工程中用jasper导出Excel报表
- JVM内存不足增大运行时内存
- 接口回调是个啥?