Java BufferedReader reset()方法及示例

BufferedReader類的reset()方法 (BufferedReader Class reset() method)

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

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

  • reset() method is used to reset the stream to the most recent mark of this stream.

    reset()方法用于將流重置為該流的最新標記。

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

    reset()方法是一種非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。

  • reset() method may throw an exception at the time of resetting this stream.

    reset()方法在重置此流時可能會引發異常。

    IOException: This exception may throw while performing input/output operation.

    IOException :在執行輸入/輸出操作時,可能會拋出此異常。

Syntax:

句法:

    public void reset();

Parameter(s):

參數:

  • It does not accept any parameter.

    它不接受任何參數。

Return value:

返回值:

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

該方法的返回類型為void ,不返回任何內容。

Example:

例:

// Java program to demonstrate the example 
// of void reset() method of 
// BufferedReader
import java.io.*;
public class ResetBR {
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);
// It reset the stream to the
// position last marked by mark
System.out.println("buff_r.reset(): ");
buff_r.reset();
// Read from the stream
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: H
ch2 : e
buff_r.mark(5):
ch3: l
buff_r.reset():
ch4: l
ch5: o

翻譯自: https://www.includehelp.com/java/bufferedreader-reset-method-with-example.aspx

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/378845.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/378845.shtml
英文地址,請注明出處:http://en.pswp.cn/news/378845.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

將兩大小完全相同的照片進行加權混合對比

將兩張大小完全相同的照片進行加權混合對比 import cv2 img1cv2.imread(E:\Python-workspace\OpenCV\OpenCV/water1.png,1)#第一個參數為選擇照片的路徑,注意照片路徑最后一個為正斜杠其他都為反斜杠;第二個參數,其中1表示所選照片為彩色照片…

過了很久了

很久沒來這里了,一般也就找找資料會上一下子。差不多算是荒廢了吧 不要緊,開始寫了轉載于:https://www.cnblogs.com/Anykong/archive/2013/02/18/2916333.html

古文中驚艷的句子

-1】終于為那一身江南煙雨覆了天下,容華謝后,不過一場,山河永寂。-2】千秋功名,一世葬你,玲瓏社稷,可笑卻無君王命。-3】鳳凰臺上鳳凰游,負約而去,一夜苦等,從此江南江北…

java 方法 示例_Java ArrayDeque pollFirst()方法與示例

java 方法 示例ArrayDeque類pollFirst()方法 (ArrayDeque Class pollFirst() method) pollFirst() Method is available in java.lang package. pollFirst()方法在java.lang包中可用。 pollFirst() Method is used to return the first element of the queue denoted by this d…

P2P技術詳解(四):P2P技術之STUN、TURN、ICE詳解

目錄1、內容概述2、STUN詳解2.1 RFC3489/STUN2.1.1 報文結構2.1.2實現原理2.1.3STUN功能舉例2.2 RFC5389/STUN2.2.1STUN用途2.2.2報文結構2.3 RFC5389與RFC3489的區別2.4 新特性介紹2.4.1指紋機制2.4.2通過DNS發現服務器機制2.4.3認證和消息完整性機制2.4.4備份服務器機制2.5 R…

比較兩張大小相同的照片的差異,返回數值

比較兩張大小相同的照片的差異,返回數值 from PIL import Image import math import operator from functools import reducedef image_contrast(img1, img2):image1 Image.open(img1)image2 Image.open(img2)h1 image1.histogram()h2 image2.histogram()resul…

poj2115C Looooops

http://poj.org/problem?id2115 參考人家的 如下 如i65534,當i3時,i1 其實就是 i(655343)%(2^16)1 有了這些思想,設對于某組數據要循環x次結束,那么本題就很容易得到方程: x[(B-A2^k)%2^k] /C 即 Cx(B-A)(mod 2^k) 此…

ASP.NET調用javascript腳本的常見方法小結

http://www.codesky.net/article/doc/201004/2010041706872.htm轉載于:https://www.cnblogs.com/ZC_Mo-Blog/archive/2010/11/23/1885125.html

python wait方法_Python條件類| 帶有示例的wait()方法

python wait方法Python Condition.wait()方法 (Python Condition.wait() Method) wait() is an inbuilt method of the Condition class of the threading module in Python. wait()是Python中線程模塊的Condition類的內置方法。 Condition class implements condition variab…

return編程python_python3 第二十一章 - 函數式編程之return函數和閉包

我們來實現一個可變參數的求和。通常情況下,求和的函數是這樣定義的:def calc_sum(*args):ax0for n inargs:ax ax nreturn ax但是,如果不需要立刻求和,而是在后面的代碼中,根據需要再計算怎么辦?可以不返回…

黑色背景下,計算照片白色的區域面積和周長

黑色背景下,計算照片白色的區域面積和周長 import cv2 img cv2.imread(E:\Python-workspace\OpenCV\OpenCV/beyond.png,1)#第一個參數為選擇照片的路徑,注意照片路徑最后一個為正斜杠其他都為反斜杠;第二個參數,其中1表示所選照…

php連接mssql數據庫的幾種方式

數據庫查詢不外乎4個步驟,1、建立連接。2、輸入查詢代碼。3、建立查詢并取出數據。4、關閉連接。 php連接mssql數據庫有幾個注意事項,尤其mssql的多個版本、32位、64位都有區別。 首先,php.ini文件中;extensionphp_pdo_mssql.dll ;extensionp…

通俗易懂:快速理解P2P技術中的NAT穿透原理

目錄1、基礎知識1.1、什么是NAT?1.2、為什么會有NAT?1.3、NAT有什么優缺點?2、NAT的實現方式2.1、靜態NAT2.2、NAPT3、NAT的主要類型3.1、完全錐型NAT(Full Cone NAT,后面簡稱FC)3.2、受限錐型NAT&#xff…

duration java_Java Duration類| toNanos()方法與示例

duration javaDuration Class toNanos()方法 (Duration Class toNanos() method) toNanos() method is available in java.time package. toNanos()方法在java.time包中可用。 toNanos() method is used to convert this Duration into the number of nanoseconds. toNanos()方…

java 負載均衡_java負載均衡 - 歲月靜好I的個人空間 - OSCHINA - 中文開源技術交流社區...

作用對系統的高可用,網絡壓力的緩解,處理能力擴容的重要手段之一。服務器負載我們通常所說的負載是指:服務器負載軟硬件負載服務器負載又分為:軟件負載--硬件負載軟件負載:通過在服務器上安裝一些具有負載功能或模塊的…

b tree和b+tree_B TREE實施

b tree和btreeB TREE及其操作簡介 (Introduction to B TREE and its operations) A B tree is designed to store sorted data and allows search, insertion and deletion operation to be performed in logarithmic time. As In multiway search tree, there are so many nod…

黑色背景下,將照片內封閉空心圖案的空心區域染成Cyan并保存

在黑色背景下,將照片內封閉空心圖案的空心區域染色 import cv2 import numpy as np img cv2.imread(E:\Python-workspace\OpenCV\OpenCV/beyond.png,1)#第一個參數為選擇照片的路徑,注意照片路徑最后一個為正斜杠其他都為反斜杠;第二個參數…

Ubuntu輸入su提示認證失敗的解決方法

Ubuntu輸入su提示認證失敗的解決方法 啟動ubuntu服務時竟然提示權限不夠,用su切換,輸入密碼提示認證失敗,這下搞了吧,后來一經查閱原來Ubuntu安裝后,root用戶默認是被鎖定了的,不允許登錄,也不允…

SDP協議基本分析(RTSP、WebRTC使用)

目錄一、介紹二、標準 SDP 規范1. SDP 的格式2. SDP 的結構(1)會話描述(2)媒體描述三、WebRTC 中的 SDP一、介紹 SDP(Session Description Protocal)以文本描述各端(PC 端、Mac 端、Android 端…

MFC六大關鍵技術(第四部分)——永久保存(串行化)

MFC 六大關鍵技術 ( 第四部分 ) ——永久保存(串行化) 先用一句話來說明永久保存的重要:弄懂它以后,你就越來越像個程序員了! 如果我們的程序不需要永久保存,那幾乎可以肯定是一個小玩兒。那怕我們的記事本…