首页 > 其他分享 >IO(四、)FileReader第一种读取方式

IO(四、)FileReader第一种读取方式

时间:2022-11-04 19:00:51浏览次数:41  
标签:fr ch java 读取 io FileReader IO catch

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;



public class FileReader1 {

public static void main(String[] args) {

FileReader fr=null;

try {

fr = new FileReader("G:\\demo.txt");

//调用读取流对象的reader方法

/*while(true){

int ch=fr.read();

if(ch==-1){

break;

}

System.out.println((char)ch);

}*/

int ch=0;

while((ch=fr.read())!=-1){

System.out.println((char)ch);

}


} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}finally{

try {

fr.close();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}




}

}

}

标签:fr,ch,java,读取,io,FileReader,IO,catch
From: https://blog.51cto.com/u_10028442/5824709

相关文章

  • Collections-sort
    importjava.util.ArrayList;importjava.util.Collections;importjava.util.List;/**1.Collections.sort(list);只能对List排序,注意:list中的*元素类型必须具备可......
  • ysoserial CommonsColletions2分析
    前言在CC2中是用的PriorityQueue#reaObject作为反序列化的入口,利用javassist创建了一个攻击类,使用TemplatesImpl类来承载他而CC1利用链在JDK1.88u71版本以后是无法使用......
  • Python文件操作 - 读取写入
    文件操作文件读取关键字with:不再需要访问文件后将其关闭函数open():接受要打开的文件名称.参数若为文件名:Python在当前执行的文件所在的目录中查找指定的文件参数为相......
  • ysoserial CommonsColletions1分析
    前言前边已经调试过Java反序列化工具ysoserial的URLDNS链,接下来看看CC链,在ysoserial工具中,并没有使用TransformedMap的来触发ChainedTransformer链,而是用了LazyMap的get方......
  • IOC控制反转
    IOC控制反转1.set注入UserDaopublicinterfaceUserDao{voidgetUser();}UserDaoImpl实现类publicclassUserDaoImplimplementsUserDao{@Overrid......
  • Transmission started to detect torrents bigger than they are
    qBittorrent使用的是MiB,GiB而Transmission使用的是MB,GB Areyousuretheunitisthesame?MaybeTransmissionsisnotusing GiB units?Ithappens,that5.......
  • 按照 ExpressionVisitor 抽象类 思路 重新实现表达式 从左到右 递归解析 解决参数编号
     核心递归方法根据表达式类型跳转到具体的处理方法处理完后返回null跳出循环///<summary>///访问///</summary>///<pa......
  • Java学习笔记day4--数组常见异常Exception
    packageday4_array;/**数组中的常见异常:1.数组角标越界的异常ArrayIndexOutOfBoundsException2.空指针异常NullPointerException*/publiccla......
  • kubernetes核心实战(三)--- ReplicationController
    5、ReplicationControllerReplicationController确保在任何时候都有特定数量的Pod副本处于运行状态。换句话说,ReplicationController确保一个Pod或一组同类的Pod总......
  • 使用 Istioctl 安装 istio
    使用Istioctl安装istio下载Istio转到Istio发布页面,下载针对你操作系统的安装文件,或用自动化工具下载并提取最新版本(Linux或macOS):[root@k8s-master-node1~]#curl......