字节缓冲流 BufferedOutputStream BufferedInputStream
2024-10-18 21:16:48
/*缓冲流:读取数据大量的文件时,读取的速度慢java提供了一套缓冲流 提高io流的效率
*
*/
package cn.lijun.demo; import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
/*
* 字节输入流的缓冲流
* 继承InputStream
* 构造方法
*/
public class BufferedInputStreamDemo {
public static void main(String[] args) throws Exception {
//创建字节输入流的缓冲流对象
BufferedInputStream bis=new BufferedInputStream(new FileInputStream("d:\\b.txt"));
byte[] b=new byte[1024];
int len=0;
while((len=bis.read(b))!=-1){
System.out.println(new String(b,0,len));
}
bis.close();
} } package cn.lijun.demo; import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
/*
* 字节输出流的缓冲流 作用 提高效率
* 继承OutputStream
* 构造方法new BufferedOutputStream(OutputStream out);
*/
public class BufferedOutputStreamDemo {
public static void main(String[] args) throws Exception {
FileOutputStream fos=new FileOutputStream("d:\\b.txt");
BufferedOutputStream bos=new BufferedOutputStream(fos); bos.write(65);
byte[] b="hello world".getBytes();
bos.write(b);
bos.write(b,3,2); //从索引为三的开始 截取两位数
bos.close();
} }
最新文章
- GridView中数据的汇总方法
- string转byte[]
- 简单实用的二级树形菜单hovertree
- 地图编辑器V3
- Construct Binary Tree from Preorder and Inorder Traversal
- How to Allow MySQL Client to Connect to Remote MySql
- [转]OBOUT ASP.NET HTML Editor - Insert HTML
- My_Python的常用函数.
- linux中deb怎样安装
- vs 设置生成的实体为复数
- C#设计模式学习资料--观察者模式
- Linux C/C++ 编程练手 --- 大数相加和大数相乘
- sys.stdout 重定向
- poj 1001 求高精度幂
- 转:js中cookie的使用详细分析
- HashMap方法介绍
- Android Studio打开项目,停在gradle的解决方案
- zuul的学习
- Week 1 工程表格
- Netty Reactor 线程模型笔记
热门文章
- 使用 Travis CI 自动部署 Hexo 站点至 GitHub Pages
- 【python练习题】程序10
- Django+Vue打造购物网站(三)
- Mining Station on the Sea HDU - 2448(费用流 || 最短路 &;&; hc)
- HDOJ5551 Huatuo's Medicine
- 自学Python之路-Python核心编程
- [luogu4072][bzoj4518][SDOI2016]征途【动态规划+斜率优化】
- table用模板生成的问题
- Nginx+Tomcat-cluster构建
- webRequest封装