Java CharArrayReader mark()方法与示例

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

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

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

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

    mark()方法用于标记流中的当前位置,并在每次调用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 void mark(int r_limit);

Parameter(s):

参数:

  • int r_limit – represents the limit on the number of character that can be read while preserving the mark.

    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 
// CharArrayReader
import java.io.*;
public class MarkOfCAR {
public static void main(String[] args) {
CharArrayReader car_stm = null;
char[] c_arr = {
'a',
'b',
'c',
'd'
};
try {
// Instantiates CharArrayReader
car_stm = new CharArrayReader(c_arr);
// By using read() method isto 
// read the character from car_stm
int i1 = car_stm.read();
int i2 = car_stm.read();
int i3 = car_stm.read();
int i4 = car_stm.read();
System.out.println("i1: " + i1);
// By using mark() method isto
// set the current position in this
// car_stm
System.out.println("car_stm.mark(0): ");
car_stm.mark(0);
System.out.println("i2: " + i2);
System.out.println("i3: " + i3);
// By using reset() method isto
// reset the stream to the position 
// set by the call mark() method
System.out.println("car_stm.reset(): ");
car_stm.reset();
System.out.println("i2: " + i2);
System.out.println("i3: " + i3);
System.out.println("i4: " + i4);
} catch (IOException e) {
System.out.print("Stream closed!!!!");
} finally {
// Free all system resources linked
// with the stream after closing
// the stream
if (car_stm != null)
car_stm.close();
}
}
}

Output

输出量

i1: 97
car_stm.mark(0): 
i2: 98
i3: 99
car_stm.reset(): 
i2: 98
i3: 99
i4: 100

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/544694.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C# Winform 窗体美化(五、鼠标穿透)

五、鼠标穿透 以前在玩射击游戏的时候,狙击枪的设定一般是开镜才有准星,所以想是不是可以自己造一个默认准星出来,思路是现在窗口上画一个准星,然后把窗体其他区域都透明,然后设置鼠标穿透; 结果是&#…

生产环境一次诡异的NPE问题,反转了4次

前言公司为了保证系统的稳定性,加了很多监控,比如:接口响应时间、cpu使用率、内存使用率、错误日志等等。如果系统出现异常情况,会邮件通知相关人员,以便于大家能在第一时间解决隐藏的系统问题。此外,我们这…

ZooKeeper学习笔记—配置管理

为什么80%的码农都做不了架构师?>>> 最近在工作中,为了完善公司集群服务的架构,提高可用性,降低运维成本,因此开始学习ZooKeeper。 至于什么是ZooKeeper?它能做什么?如何安装ZooKee…

Java BigDecimal compareTo()方法与示例

BigDecimal类compareTo()方法 (BigDecimal Class compareTo() method) compareTo() method is available in java.math package. compareTo()方法在java.math包中可用。 compareTo() method is used to compare this BigDecimal object to the given object or in other words …

C# Winform 窗体美化(六、双层窗体)

六、双层窗体 大概情况 双层床体是为了平滑的创建异形窗体的一个解决方案,找了很多资料,整理了一下。 双层窗体的逻辑是建立在 UpdateLayeredWindow 不能绘制控件的基础上,上层再添加一个专门放置控件的层;这样就可以在上层“控…

批处理框架 Spring Batch 这么强,你会用吗?

来源:blog.csdn.net/topdeveloperr/article/details/84337956spring batch简介Spring Batch架构介绍Spring Batch核心概念介绍chunk 处理流程批处理操作指南spring batch简介 spring batch是spring提供的一个数据处理框架。企业域中的许多应用程序需要批量处理才能在…

Android Bundle类别

即使在今天发现自己Bundle类不明确,因此,花时间去研究了一下。 依据google官方文件(http://developer.android.com/reference/android/os/Bundle.html) Bundle类是一个key-value对,“A mapping from String values to …

C# Winform 窗体美化(七、Win7 Aero 毛玻璃效果)

七、Win7 Aero 毛玻璃效果 在 Win7 上有一种 Aero 效果,毛玻璃透明效果,搭配不同风格的颜色,效果很好。在学习 Winform 美化的时候顺便看到的这种效果,也整理进来了。 注意:Win7 上想看到这种效果需要开启并使用 Aer…

非导向传输媒体| 计算机网络

Transmission media can be categorized in two ways, 传输媒体可以通过两种方式进行分类: Guided Transmission Media 引导传输媒体 Unguided Transmission Media 非引导传输媒体 1)非引导传输媒体 (1) Unguided Transmission Media) It is also called wireless …

面霸篇:MQ 的 5 大关键问题详解

最近mq越来越火,很多公司在用,很多人在用,其重要性不言而喻。但是如果我让你回答下面的这些问题:我们为什么要用mq?引入mq会多哪些问题?如何解决这些问题?你心中是否有答案了呢?本文…

C# Winform 窗体美化(八、Icon)

八、Icon 之前 Winform 项目也有在 Icon 上遇到些问题(这里的 Icon 指的是 .ico 类型的文件),比如刚开始不知道怎么让自己的程序 Icon 和其他软件一样可以放大,还有放大之后在音量合成器中会出现比较奇葩的效果之类的问题&#x…

Java LocalDate类| 带示例的getEra()方法

LocalDate类的getEra()方法 (LocalDate Class getEra() method) getEra() method is available in java.time package. getEra()方法在java.time包中可用。 getEra() method is used to get the era applicable for this LocalDate object. getEra()方法用于获取适用于此LocalD…

MyBatis 的执行流程,学废了!

作者:双子孤狼来源:blog.csdn.net/zwx900102/article/details/108455514MyBatis可能很多人都一直在用,但是MyBatis的SQL执行流程可能并不是所有人都清楚了,那么既然进来了,通读本文你将收获如下:1、Mapper接…

C# Winform 窗体美化(九、嵌入窗体)

九、嵌入窗体 还是关于 Winform 窗体的一些操作问题,这次是研究了一个嵌入窗体,这次学习纯属偶然,项目中确实没遇到过这种需求。就是把别人的程序嵌入到自己的程序中,就像这样: 这里我嵌入了测试显示器的程序 [外链图…

Mac 流程图

https://www.lucidchart.com/pages/signup?utm_expid39895073-174.qKyHpBEbQS26y86OArD-rQ.1 https://www.processon.com/

setname_Python线程类| setName()方法与示例

setnamePython Thread.setName()方法 (Python Thread.setName() Method) Thread.setName() method is an inbuilt method of the Thread class of the threading module in Python. It uses a Thread object and sets the name of the thread. Thread.setName()方法是Python中线…

SpringBoot 优雅的参数效验!

引言 不知道大家平时的业务开发过程中 controller 层的参数校验都是怎么写的?是否也存在下面这样的直接判断?public String add(UserVO userVO) {if(userVO.getAge() null){return "年龄不能为空";}if(userVO.getAge() > 120){return &quo…

NTFS Change Journal(USN Journal)详解

写在前面 最近又用了一下usn日志来获取所有文件列表,在分多次加载文件列表的时候发现有文件丢失的情况,后来发现一篇文章比较详细的讲了usn。 用cmd来读取usn日志 如图: 以下是转载内容: 还是那个文件监控的应用,…

Java即时类| hashCode()方法与示例

即时类hashCode()方法 (Instant Class hashCode() method) hashCode() method is available in java.time package. hashCode()方法在java.time包中可用。 hashCode() method is used to get the hash code value for this Instant. hashCode()方法用于获取此Instant的哈希码值…

系统起动时加载的过程

sof_getdjval转载于:https://blog.51cto.com/bks2015/1660178