IO流6 --- FileReader中使用read(char[] cbuf)读入数据 --- 技术搬运工(尚硅谷)
2024-09-18 19:44:12
- FileReader 字符输入流
@Test
public void test2(){
File file = new File("hello.txt");
FileReader fr = null;
try {
fr = new FileReader(file);
char[] cbuf = new char[5];
//返回读取的长度
int len;
while ((len = fr.read(cbuf)) != -1){
String str = new String(cbuf, 0, len);
System.out.print(str);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
if (fr != null){
try {
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
最新文章
- 如何在本地搭建IIS服务器
- 玩转CSS3,嗨翻WEB前端,CSS3伪类元素详解/深入浅出[原创][5+3时代]
- 【SVN】自动备份SVN仓库
- 解决-bash: lsb_release: command not found
- sleep()
- poj 1190 生日蛋糕
- 使用Cookie保存商品浏览记录
- Distant Supervision for relation extraction without labeled data
- [改善Java代码]推荐使用枚举定义常量
- [未完成][Mooc]关于Linxu的总结(一)
- php关于private、public成员变量访问问题
- 代码生成引擎之T4模版
- Codeforces Beta Round #10 B. Cinema Cashier (树状数组)
- 2016 ACM/ICPC Asia Regional Qingdao Online
- nmon安装(转)
- js 去除html标签
- javascript四舍五入tofixed
- Hibernate第十篇【Hibernate查询详解、分页查询】
- php实现MySQL读写分离
- MTF 曲线图解读