1.fileReader是字符的读出,只能读文件.

2.在读取文件的之前,该文件必须存在.

3.int reader();一次读取一个字符,返回的该字符的码值,如果想要返回字符,直接进行强转char

4.int reader(char[] buf);一次读取一个字符数组,返回每次读取元素的个数

5.怎样判断读取的数据是否到结尾  fileReader.reader() =-1

/**
*
* @author Administrator
* 文件的读FileReader(字符的读)
* 文件的写FileWriter(字符的写)
*/
public class FileTest { public static void main(String[] args) throws IOException {
fileReaderTest();
}
/**
* 字符读
* @throws IOException
*/
public static void fileReaderTest() throws IOException{ //1.创建文件对象
File file = new File("a.txt");
//2.创建字符读流对象
FileReader fr = new FileReader(file); //3.一个字符一个字符的读取文件,返回的字节的码值
int read = fr.read();
System.out.println("一个字节一个字节读:"+read); //4.一个字符数组一个字符数组的读,返回的每次读取的个数
char[] chars = new char[1024];
int read2 = fr.read(chars);
System.out.println("一次读取的个数"+read2);
System.out.println("每次读取的char数组:"+Arrays.toString(chars)); //5.读取文件中的所有内容
char[] charts = new char[3];
int len;
while((len = fr.read(charts)) != -1){
System.out.println(new String(charts, 0, len));
}
//4.关闭读流
fr.close();
} }

FileReader字符的读出的更多相关文章

  1. java IO通过字节流,字符流 读出写入

    一:通过字节流操作数据的写入,读出 /** * 通过字节流写入和读出 * @param args */ public static String filePath = "G:" + ...

  2. FileWriter字符输出流和FileReader字符输出流

    //FileWriter public class FileWriterDemo { //字符流:适用于文本文件,以字符为单位进行操作,经常和缓冲流一起使用 /**  * 字符流操作步骤:  * 1. ...

  3. java的文件流:字节流(FileInputStream、FileOutputStream)和字符流(FileReader、FileWriter)。

    java的输入输出建立在4个抽象类的基础上:InputStream.OutputStream.Reader.Writer.InputSream和OutputStream被设计成字节流类,而Reader ...

  4. JAVA基础学习day19--IO流一、FileWrite与FileReader

    一.IO简述 1.1.简述 IO:input/output IO流用来处理设备之间的数据传输 Java对数据的操作是通过流的方式 Java用于操作流的对象都在IO包中. 1.2.结构 字节流抽象类: ...

  5. 简单linux字符设备驱动程序

    本文代码参考<LINUX设备驱动程序>第三章 字符设备驱动程序 本文中的“字符设备”是一段大小为PAGE_SIZE的内存空间 功能:向字符设备写入字符串:从字符设备读出字符串 代码: 1. ...

  6. Java基础:IO流之字节流和字符流

    1. 流的概念 流(stream)的概念源于UNIX中管道(pipe)的概念.在UNIX中,管道是一条不间断的字节流,用来实现程序或进程间的通信,或读写外围设备.外部文件等. 一个流,必有源端和目的端 ...

  7. IO流6 --- FileReader中使用read(char[] cbuf)读入数据 --- 技术搬运工(尚硅谷)

    FileReader 字符输入流 @Test public void test2(){ File file = new File("hello.txt"); FileReader ...

  8. IO流5 --- FileReader读入数据的基本操作 --- 技术搬运工(尚硅谷)

    FileReader 字符输入流 @Test public void test1(){ File file = new File("hello.txt"); FileReader ...

  9. 【java】学习路径42-六种字符流使用实例

    第一种 OutputStreamWriter OutputStreamReader 第二种 FileWriter FileReader 第三种 BufferedWriter BufferedReade ...

随机推荐

  1. 为什么python中没有switch case语句

    终于知道了python中映射的设计哲学. 我自己写的code : class order_status_switcher(object): def get_order_status(self,argu ...

  2. python基础(6)-深浅拷贝

    赋值 字符串和数字 # id()函数可以获取变量在内存中的地址标识 num1 = 2; num2 = 2; print(id(num1)) # result:8791124202560 print(i ...

  3. postgres密码修改

    . 修改PostgreSQL数据库默认用户postgres的密码 PostgreSQL数据库创建一个postgres用户作为数据库的管理员,密码随机,所以需要修改密码,方式如下: 步骤一:登录Post ...

  4. JavaScript 常用数组函数方法专题

    1. 由字符串生成数组 split() 分割字符串,并将分割的部分作为一个元素保存在一个新建的数组中. var str1 = "this is an emample to using the ...

  5. git----------SourceTree如何连接ssh的仓库地址,这里记录的是客户端需要做的事

    1. 2. 打开命令行以后输入ssh-keygen -t rsa -C "example@example.com"  这个地方输入的是你注册gitlab所使用的邮箱.按回车,之后还 ...

  6. Linux系统查看本机ip地址

    1. 使用ifconfig命令查看inet对应的ip地址就是 2. 如果不能使用ifconfig命令,需要安装net-tools工具,使用yum install net-tools安装即可.

  7. jupyter notebook新用法

    输入单词以后按下tab键以后 出现提示 a是个矩阵或者数组,a.flatten()就是把a降到一维,默认是按横的方向降>>> a = np.array([[1,2], [3,4]]) ...

  8. codeforces #305 C Mike and Foam

    首先我们注意到ai<=50w 因为2*3*5*7*11*13*17=510510 所以其最多含有6个质因子 我们将每个数的贡献分离, 添加就等于加上了跟这个数相关的互素对 删除就等于减去了跟这个 ...

  9. Maven Web Projest经Update Projest报错:Cannot nest 'myApp/src/main/resource' inside 'myApp/src'. To enable the nesting exclude 'main/' from 'myApp/src'

    1,报错场景 2,解决方法 修改pom.xml,去掉该行:<sourceDirectory>src/</sourceDirectory>

  10. Netty源码分析之服务端启动

    Netty服务端启动代码: public final class EchoServer { static final int PORT = Integer.parseInt(System.getPro ...