java reader_Java Reader reset()方法與示例

java reader

讀取器類的reset()方法 (Reader Class reset() method)

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

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

  • reset() method is used to reset this stream to the mark set by mark() method most recently.

    reset()方法用于將此流重置為mark()方法最近設置的標記。

  • 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 the stream.

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

    IOException: This exception may throw when getting any input/output error or unsupported reset() method.

    IOException :當遇到任何輸入/輸出錯誤或不受支持的reset()方法時,可能引發此異常。

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 Reader
import java.io.*;
public class ResetOfR {
public static void main(String[] args) throws Exception {
Reader r_stm = null;
try {
// Instantiates Reader
r_stm = new StringReader("JavaWorld!!!!");
// By using read() method isto 
// read the character from r_stm
char ch1 = (char) r_stm.read();
char ch2 = (char) r_stm.read();
char ch3 = (char) r_stm.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
// r_stm
System.out.println("r_stm.mark(1): ");
r_stm.mark(1);
char ch4 = (char) r_stm.read();
char ch5 = (char) r_stm.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("r_stm.reset(): ");
r_stm.reset();
char ch6 = (char) r_stm.read();
char ch7 = (char) r_stm.read();
char ch8 = (char) r_stm.read();
char ch9 = (char) r_stm.read();
char ch10 = (char) r_stm.read();
char ch11 = (char) r_stm.read();
char ch12 = (char) r_stm.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);
System.out.println("ch10: " + ch12);
} 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 (r_stm != null) {
r_stm.close();
}
}
}
}

Output

輸出量

ch1: J
ch2: a
ch3: v
r_stm.mark(1): 
ch4: a
ch5: W
r_stm.reset(): 
ch4: a
ch5: W
ch6: o
ch7: r
ch8: l
ch9: d
ch10: !

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

java reader

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

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

相關文章

leetcode 501. 二叉搜索樹中的眾數 思考分析

目錄題目1、不考慮BTS性質,直接尋找眾數集合(利用map)2、考慮BTS的中序遍歷結果性質題目 給定一個有相同值的二叉搜索樹(BST),找出 BST 中的所有眾數(出現頻率最高的元素)。 假定 BS…

二、模型評估方法

IDE為Jupyter Notebook scikit-learn官網 scikit-learn是一個專門用于機器學習的工具包 運用到啥函數不知道咋使用?戳它–>scikit-learn工具包的API文檔 不知道用啥模板?戳它–>scikit-learn樣例模型 功能翻譯Classification分類Regression回歸Cl…

union

關鍵字 1. 共用體聲明和共用體變量定義共用體(參考“共用體”百科詞條)是一種特殊形式的變量,使用關鍵字union來定義共用體(有些人也叫"聯合")聲明和共用體變量定義與結構體十分相似。其形式為:union 共用體名{數據類型 成員名;數據類型 成員名;...} 變量…

SEL

Object-C 中的Selector 概念 Andrew Huang <bluedrum163.com> 轉載請注明作者和聯絡方式 在iphone程序中會大量看到selector這樣的用法。<<iphone開發基礎>花了很大一個篇幅來解析這個語法&#xff0c;但是不知 是翻譯問題&#xff0c;還是解釋過細&#xff0c…

Java Calendar add()方法與示例

日歷類的add()方法 (Calendar Class add() method) add() method is available in java.util package. add()方法在java.util包中可用。 add() method is used to perform add or subtract the given amount of time to the given cal_fi (calendar field). add()方法用于對指定…

三、線性回歸實驗分析

所有代碼塊都是在Jupyter Notebook下進行調試運行&#xff0c;前后之間都相互關聯。 文中所有代碼塊所涉及到的函數里面的詳細參數均可通過scikit-learn官網API文檔進行查閱&#xff0c;這里我只寫下每行代碼所實現的功能&#xff0c;參數的調整讀者可以多進行試驗調試。多動手…

leetcode 236. 二叉樹的最近公共祖先 思考分析

目錄題目思考分析改進本文章代碼思路來源于公眾號【代碼隨想錄】題目 給定一個二叉樹, 找到該樹中兩個指定節點的最近公共祖先。 百度百科中最近公共祖先的定義為&#xff1a;“對于有根樹 T 的兩個結點 p、q&#xff0c;最近公共祖先表示為一個結點 x&#xff0c;滿足 x 是 p、…

輕輕松松給PCB板添加LOGO

在 PCB 圖中放置漢字或圖形的方法&#xff1a;A、文字——> 圖片——> PCB 圖——> 復制到自己作品中B、圖片——> PCB 圖——> 復制到自己作品中1、首先準備好“BMP”格式的圖片&#xff0c;在圖片中依靠顏色分辨圖層&#xff0c;所以最好準備“單色黑白”圖。…

java bitset_Java BitSet clone()方法及示例

java bitsetBitSet類clone()方法 (BitSet Class clone() method) clone() method is available in java.util package. clone()方法在java.util包中可用。 clone() method is used to clone this Bitset or in other words, this method is used to create a Bitset that is si…

小技巧

//屏蔽下拉框的某一個選項 <disabled"disable">... 1 <html>2 <body>3 4 <select>5 <option>Volvo</option>6 <option>Saab</option>7 <option disabled"disabled">Mercedes</option>…

jquery中text val html attr的差別

html和innerHTMl是一樣的&#xff0c;可以獲得和設置html標簽文本如&#xff1a;設置值&#xff1a;$("p").html("<span stylefont-size:13px;color:red>HTML標簽文本</span>"); 獲得值&#xff1a;$("p").html(); text和innerText是…

leetcode 235. 二叉搜索樹的最近公共祖先 思考分析

目錄題目思考迭代法題目 給定一個二叉搜索樹, 找到該樹中兩個指定節點的最近公共祖先。 百度百科中最近公共祖先的定義為&#xff1a;“對于有根樹 T 的兩個結點 p、q&#xff0c;最近公共祖先表示為一個結點 x&#xff0c;滿足 x 是 p、q 的祖先且 x 的深度盡可能大&#xff0…

四、邏輯回歸

邏輯回歸logistic_regression(LR)其實是分類算法&#xff0c;而不是回歸算法。 回歸算法得到的是一個數&#xff0c;分類算法得到的是幾個不同的類別。 邏輯回歸就是通過函數將值轉換為0-1之間&#xff0c;形成概率問題&#xff0c;從而實現了不同類別的分類。 Sigmoid 函數 …

db,dbms,dba_DBMS中的數據庫管理員(DBA)

db,dbms,dba數據庫管理員(DBA) (Database Administrator (DBA)) To use the Database Management System, it is necessary to have central control over data and programs together in order to access such data. A person who has central control over such system is re…

運算符優先級

轉載于:https://www.cnblogs.com/c-cloud/p/3280911.html

五、邏輯回歸實驗分析

所有代碼塊都是在Jupyter Notebook下進行調試運行&#xff0c;前后之間都相互關聯。 文中所有代碼塊所涉及到的函數里面的詳細參數均可通過scikit-learn官網API文檔進行查閱&#xff0c;這里我只寫下每行代碼所實現的功能&#xff0c;參數的調整讀者可以多進行試驗調試。多動手…

二叉搜索樹的插入、刪除、修剪、構造操作(leetcode701、450、669、108)

目錄1、leetcode 701. 二叉搜索樹中的插入操作1、題目2、遞歸法3、迭代法2、leetcode 450. 二叉搜索樹中的插入操作1、題目2、思路遞歸法3、迭代法4、刪除結點的兩個方法以及注意點3、leetcode 669. 修剪二叉搜索樹1、題目2、思考與遞歸3、迭代法4、leetcode 108. 將有序數組轉…

Memcached查看和清理

1.一種telnet localhost 11211 #登陸stats #查看狀態flush_all #清理quit #退出2.又學到一個:echo flush_all | nc localhost 112113.1、數據存儲(假設key為test,value為12345) printf "set test 0 1 5\r\n12345\r\n" | nc localhost 11211STORED2.數據取回(假設key為…

模擬退火算法解決np_P和NP問題與解決方案| 演算法

模擬退火算法解決npP問題 (P Problems) P is the set of all the decision problems solvable by deterministic algorithms in polynomial time. P是多項式時間內確定性算法可解決的所有決策問題的集合。 NP問題 (NP Problems) NP is the set of all the decision problems t…

POJ2251Dungeon Master

http://poj.org/problem?id2251 題意 &#xff1a; 就是迷宮升級版&#xff0c;從以前的一個矩陣也就是一層&#xff0c;變為現在的L層&#xff0c;" . "是可以走&#xff0c;但是“#”不可以走&#xff0c;從S走到E&#xff0c;求最短的路徑&#xff0c;若是找不到…