RandomAccessFile类readChar()方法 (RandomAccessFile Class readChar() method)

  • readChar() method is available in java.io package.

    readChar()方法在java.io包中可用。

  • readChar() method is used to read a character value from this file and it can read character up to 2 bytes from the file.

    readChar()方法用于从此文件读取字符值,它可以从文件读取最多2个字节的字符。

  • readChar() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    readChar()方法是一种非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • readChar() method may throw an exception at the time of reading char.

    readChar()方法在读取char时可能会引发异常。

    • IOException: This exception may throw an exception while performing input/output operation.IOException :在执行输入/输出操作时,此异常可能会引发异常。
    • EOFException: This exception may throw when the file pointer reaches EOF (End-Of-File) before reading 2 bytes.EOFException :当文件指针在读取2个字节之前到达EOF(文件末尾)时,可能引发此异常。

Syntax:

句法:

    public final char readChar();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of this method is char, it returns the character of next 2 bytes from this file.

该方法的返回类型为char ,它从该文件返回下一个2个字节的字符。

Example:

例:

// Java program to demonstrate the example
// of char readChar() method of
// RandomAccessFile
import java.io.*;
class RAFReadChar {public static void main(String[] args) throws Exception {// Instantiate a random access file
// object with file name and permissions
RandomAccessFile ra_f = new RandomAccessFile("e:/includehelp.txt", "rw");
// By using writeChar() method is to
// write character to the file
ra_f.writeChar('I');
// Initially set the file pointer
// is at 0 for reading the file
ra_f.seek(0);
// By using readChar() method is to
// read character from the file
char ch = ra_f.readChar();
System.out.println("ra_f.readChar(): " + ch);
// By using close() method isto
// close this stream ran_f
ra_f.close();
}
}

Output

输出量

ra_f.readChar(): I

翻译自: https://www.includehelp.com/java/randomaccessfile-readchar-method-with-example.aspx

Java RandomAccessFile readChar()方法及示例相关推荐

  1. Java IOUtils.copy方法代码示例(亲测)

    本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...

  2. java user directory,Java ProcessBuilder directory()方法与示例

    语法:public File directory (); public ProcessBuilder directory (File dir); ProcessBuilder类directory()方 ...

  3. Java序列化魔术方法及其示例使用

    在上一篇文章中, 您需要了解有关Java序列化的所有知识 ,我们讨论了如何通过实现Java序列化来启用类的可序列化性. Serializable接口. 如果我们的类未实现Serializable接口, ...

  4. catalog java,Java Connection getCatalog()方法与示例

    通常,目录是一个目录,其中包含有关数据集,文件或数据库的信息.而数据库目录中包含所有数据库,基本表,视图(虚拟表),同义词,值范围,索引,用户和用户组的列表. Connection接口的getCata ...

  5. filepermission java,Java FilePermission getActions()方法与示例

    FilePermission类getActions()方法getActions()方法在java.io包中可用. getActions()方法用于检查此FilePermission和给定对象在路径名和 ...

  6. java方法参数Bundle,Java ResourceBundle keySet()方法及示例

    ResourceBundle类keySet()方法keySet()方法在java.util包中可用. keySet()方法用于从此ResourceBundle及其超级捆绑包中获取所有现有键,以在Set ...

  7. java exec waitfor,Java Process waitFor()方法与示例

    流程类waitFor()方法在java.lang包中提供了waitFor()方法. waitFor()方法用于使当前正在运行的线程在需要时等待,直到由该Process对象表示的进程完成其终止为止. 当 ...

  8. java arraylist.add(),Java ArrayList add()方法与示例

    ArrayList类add()方法 语法:public boolean add(T ele); public void add(int indices, T ele);add()方法在java.uti ...

  9. java rollback用法,Java Connection rollBack()方法与示例

    回滚操作将撤消当前事务所做的所有更改,即,如果调用Connection接口的rollBack()方法,则所有修改都将还原到最后一次提交. 您还可以通过将所需的Savepoint对象作为参数传递给此方法 ...

最新文章

  1. Xamarin.FormsShell基础教程(5)Shell项目内容新建页面
  2. 单应性矩阵和仿射变换_单应矩阵 基本矩阵 本质矩阵的区别与联系
  3. SharedPreferences保存对象以及集合,腾讯MMKV使用,保存搜索历史
  4. 解决重启centos后resolv.conf总被清空的问题
  5. 洛谷P1120【小木棍】(搜索+剪枝)
  6. 使用计算机打印资料时需要安装打印机驱动,打印机驱动安装步骤详解(一)_电脑基础知识_IT计算机_专业资料...
  7. 计算机专业 外文数据库,计算机专业外文翻译+原文-数据库管理系统介绍
  8. 一味顺从的人没有好果子吃
  9. 线性代数笔记19——格拉姆-施密特正交化
  10. 质控三张图 gaochao ards 多个表型写成循环
  11. 提升性能的开发者选项,华为手机必开4种设置,让手机飞起来
  12. android app增加内存大小,硬件不够软件来凑:如何提升Android手机运行内存?
  13. 给PPT插入页码和总页码
  14. nth-child 与 nth-of-type
  15. SSD 1306显示屏 adafruit SSD 1306
  16. 判断字符串中是否具有唯一字符
  17. 揭秘京东城市时空数据引擎—JUST如何助力交通流量预测
  18. OBS点播电影电视剧添加场景
  19. 用Windows电脑看txt小说,阅读器软件怎么选
  20. LSI(潜在语义索引)主题建模简介

热门文章

  1. 计算机网络画出发送窗口变化,全国2010年7月自考计算机网络原理试题及答案
  2. python程序打包成安卓app教程_Python打包方法基本应用方式介绍
  3. python字符串变量s的值是python网络爬虫_【Python爬虫作业】-字符串
  4. mysql 导入 mssql_MySQL(csv,text)导入mssql使用方法
  5. 3090显卡 torch.cuda.is_available()返回false的解决办法
  6. Git基础知识教程整理(Git基本操作)
  7. Babylon-AST初探-代码更新删除(Update Remove)
  8. python生成器与迭代器。
  9. day5-shutil模块
  10. 【学习笔记】java核心技术学习笔记整理