LineNumberReader类mark()方法 (LineNumberReader Class mark() method)

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

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

  • mark() method is used to set the current position in this LineNumberReader stream and whenever we call to reset() so it will reset the stream to the position set by the most recent call of mark() method.

    mark()方法用于设置此LineNumberReader流中的当前位置,并且每当我们调用reset()时,它将它将流重置为由mark()方法的最新调用设置的位置。

  • mark() 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.

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

  • mark() method may throw an exception at the time of marking the stream.

    mark()方法在标记流时可能会引发异常。

    IOException: This exception may throw when the given parameter is not valid.

    IOException :如果给定参数无效,则可能引发此异常。

Syntax:

句法:

    public int mark();

Parameter(s):

参数:

  • int r_limit – represents the limit on the number of characters that can be read before the mark gets invalid.

    int r_limit –表示标记无效之前可以读取的字符数限制。

Return value:

返回值:

The return type of the method is void, it returns nothing.

该方法的返回类型为void ,不返回任何内容。

Example:

例:

// Java program to demonstrate the example
// of void mark(int r_limit) method of
// LineNumberReader
import java.io.*;
public class MarkOfLNR {public static void main(String[] args) throws Exception {FileReader fr_stm = null;
LineNumberReader line_r = null;
int val = 0;
try {// Instantiates FileReader and LineNumberReader
fr_stm = new FileReader("D:\\includehelp.txt");
line_r = new LineNumberReader(fr_stm);
// By using read() method isto
// read the character from line_r
char ch1 = (char) line_r.read();
char ch2 = (char) line_r.read();
char ch3 = (char) line_r.read();
System.out.println("ch1: " + ch1);
System.out.println("ch2: " + ch2);
System.out.println("ch3: " + ch3);
// By using mark() method isto
// set the current position in this
// line_r
System.out.println("line_r.mark(0): ");
line_r.mark(0);
char ch4 = (char) line_r.read();
char ch5 = (char) line_r.read();
System.out.println("ch4: " + ch4);
System.out.println("ch5: " + ch5);
// By using reset() method isto
// reset the stream to the position
// set by the call mark() method
System.out.println("line_r.reset(): ");
line_r.reset();
char ch6 = (char) line_r.read();
char ch7 = (char) line_r.read();
char ch8 = (char) line_r.read();
char ch9 = (char) line_r.read();
char ch10 = (char) line_r.read();
char ch11 = (char) line_r.read();
System.out.println("ch4: " + ch6);
System.out.println("ch5: " + ch7);
System.out.println("ch6: " + ch8);
System.out.println("ch7: " + ch9);
System.out.println("ch8: " + ch10);
System.out.println("ch9: " + ch11);
} catch (Exception ex) {System.out.println(ex.toString());
} finally {// with the help of this block is to
// free all necessary resources linked
// with the stream
if (fr_stm != null) {fr_stm.close();
if (line_r != null) {line_r.close();
}
}
}
}
}

Output

输出量

ch1: J
ch2: A
ch3: V
line_r.mark(0):
ch4: A
ch5: W
line_r.reset():
ch4: A
ch5: W
ch6: O
ch7: R
ch8: L
ch9: D

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

Java LineNumberReader mark()方法与示例相关推荐

  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. Ruby用SciTE输出中文报错问题解决
  2. poj 1015 Jury Compromise_dp
  3. jQuery中实现全选功能时使用attr( )改变checked值只能生效一次的问题
  4. c++静态成员变量使用前必须初始化,那么下面这个例子为什么不用初始化?
  5. php ajax 更改状态,phpajax实现无刷新获取天气状态_PHP教程
  6. Xcode 自动对齐 插件
  7. Linux系统出现验证码乱码的原因及解决办法
  8. sublime text3 之 ctags
  9. 从零开始刷Leetcode——数组(27.35.53)
  10. 终面后拿offer几率_战绩 | 恭喜VIP学员斩获德勤(北京)风险分析师全职Offer!...
  11. Hadoop简单介绍
  12. 4. Podfile 的解析逻辑
  13. Windows - 电脑屏幕眼睛保护色的取值
  14. 360路由器v2刷第三方固件_路由器刷固件图文教程,刷机OpenWrt第三方固件,路由器升级固件...
  15. ionic android 教程,Ionic Capacitor Android环境搭建 创建项目
  16. 英飞凌XC2000系列单片机FLASH加解密策略
  17. 无侵入式的mysql的binlog采集——maxwell采集binlog放到kafka中——成功!
  18. boost noncopyable实现与ADL
  19. html 波斯语 对齐,在htm中使用波斯语字体发送大量HTML电子邮件
  20. 力扣 532. 数组中的 k-diff 数对

热门文章

  1. 网页无法调用java9_JAVA 9 (内部类,异常,包)
  2. eplan单线原理图多线原理图_EPLAN-黑盒-2
  3. microbit编程_使用图形化编程实现主控板与手机蓝牙通讯(2019.3.25)
  4. 华为4g模块 linux驱动程序,定制Android之4G-LTE模块驱动
  5. Mysql保存是事件驱动吗_【CHRIS RICHARDSON 微服务系列】事件驱动的数据管理-5
  6. SQLPlus命令详细说明
  7. 【PHP 扩展开发】Zephir 基础篇
  8. WPF TextBox 正则验证 大于等于0 小于等于1 的两位小数
  9. centos 6 安装zabbix 3.0
  10. DirectX 矩阵