博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java BufferedReader mark()方法与示例
阅读量:2531 次
发布时间:2019-05-11

本文共 2720 字,大约阅读时间需要 9 分钟。

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

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

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

  • mark() method is used to mark the current position in this stream and whenever we call reset() method so it will reset the stream to the given point (read_from_here).

    mark()方法用于标记此流中的当前位置,并且每当我们调用reset()方法时,都会将流重置到给定点(read_from_here)。

  • 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 setting a limit.

    设置限制时, mark()方法可能会引发异常。

    • IllegalArgumentException: This exception may throw when the given parameter is negative.IllegalArgumentException :如果给定参数为负,则可能引发此异常。
    • IOException: This exception may throw while performing input/output operation.IOException :在执行输入/输出操作时,可能会抛出此异常。

Syntax:

句法:

public void mark(int read_from_here);

Parameter(s):

参数:

  • int read_from_here – represents the number of bytes to read during mark() preserves.

    int read_from_here –表示mark()保留期间要读取的字节数。

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 read_from_here) method of // BufferedReaderimport java.io.*;public class MarkBR {
public static void main(String[] args) throws Exception {
// To open text file by using // FileInputStream FileInputStream fis = new FileInputStream("e:/includehelp.txt"); // Instantiates InputStreamReader InputStreamReader inp_r = new InputStreamReader(fis); // Instantiates BufferedReader BufferedReader buff_r = new BufferedReader(inp_r); // Read character from the stream char ch1 = (char) buff_r.read(); char ch2 = (char) buff_r.read(); char ch3 = (char) buff_r.read(); System.out.println("ch1: " + ch1); System.out.println("ch2 : " + ch2); // By using mark() method isto // set the limit the number of byte // to be read System.out.println("buff_r.mark(5): "); buff_r.mark(5); System.out.println("ch3: " + ch3); // reset stream by using reset() System.out.println("buff_r.reset(): "); buff_r.reset(); // Read from the stread char ch4 = (char) buff_r.read(); char ch5 = (char) buff_r.read(); // Display character System.out.println("ch4: " + ch4); System.out.println("ch5: " + ch5); fis.close(); inp_r.close(); buff_r.close(); }}

Output

输出量

ch1: Hch2 : ebuff_r.mark(5):ch3: lbuff_r.reset():ch4: lch5: o

翻译自:

转载地址:http://xotzd.baihongyu.com/

你可能感兴趣的文章
阶段3 3.SpringMVC·_07.SSM整合案例_04.ssm整合之编写SpringMVC框架
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第1节零基础快速入门SpringBoot2.0_5、SpringBoot2.x的依赖默认Maven版本...
查看>>
阶段3 3.SpringMVC·_07.SSM整合案例_08.ssm整合之Spring整合MyBatis框架
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第2节 SpringBoot接口Http协议开发实战_9、SpringBoot基础HTTP其他提交方法请求实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第2节 SpringBoot接口Http协议开发实战_12、SpringBoot2.x文件上传实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第4节 Springboot2.0单元测试进阶实战和自定义异常处理_19、SpringBoot个性化启动banner设置debug日志...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第4节 Springboot2.0单元测试进阶实战和自定义异常处理_20、SpringBoot2.x配置全局异常实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第5节 SpringBoot部署war项目到tomcat9和启动原理讲解_23、SpringBoot2.x启动原理概述...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第4节 Springboot2.0单元测试进阶实战和自定义异常处理_21、SpringBoot2.x配置全局异常返回自定义页面...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第8节 数据库操作之整合Mybaties和事务讲解_32..SpringBoot2.x持久化数据方式介绍...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第8节 数据库操作之整合Mybaties和事务讲解_34、SpringBoot整合Mybatis实操和打印SQL语句...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第8节 数据库操作之整合Mybaties和事务讲解_35、事务介绍和常见的隔离级别,传播行为...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第9节 SpringBoot2.x整合Redis实战_40、Redis工具类封装讲解和实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第9节 SpringBoot2.x整合Redis实战_37、分布式缓存Redis介绍...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第10节 SpringBoot整合定时任务和异步任务处理_42、SpringBoot常用定时任务配置实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第9节 SpringBoot2.x整合Redis实战_39、SpringBoot2.x整合redis实战讲解...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第14节 高级篇幅之SpringBoot多环境配置_59、SpringBoot多环境配置介绍和项目实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第10节 SpringBoot整合定时任务和异步任务处理_41、SpringBoot定时任务schedule讲解...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第10节 SpringBoot整合定时任务和异步任务处理_43、SpringBoot2.x异步任务实战(核心知识)...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_1_01课程简介
查看>>