Java ByteArrayInputStream reset()方法及示例

ByteArrayInputStream類reset()方法 (ByteArrayInputStream Class reset() method)

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

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

  • reset() method is used to reset this ByteArrayInputStream to the last time marked position and when no user defines mark position set so it takes default mark position i.e. 0.

    reset()方法用于將此ByteArrayInputStream重置為上次標記的位置,并且在沒有用戶定義標記位置的情況下,它使用默認標記位置,即0。

  • 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 does not throw an exception at the time of reset this stream.

    在重置此流時, 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
// ByteArrayInputStream
import java.io.*;
public class ResetBAIS {
public static void main(String[] args) throws Exception {
byte[] by = {
97,
98,
98,
99
};
// Instantiates ByteArrayInputStream 
ByteArrayInputStream byte_s = new ByteArrayInputStream(by);
// By using available() method is to
// return the no. of bytes to be left 
// for reading
Integer n_byte = byte_s.available();
System.out.println("Left avail bytes = " + n_byte);
// Read character from the stream
char ch1 = (char) byte_s.read();
char ch2 = (char) byte_s.read();
char ch3 = (char) byte_s.read();
System.out.println("ch1: " + ch1);
System.out.println("ch2 : " + ch2);
System.out.println("byte_s.mark(5): ");
// By using mark() method isto
// set the limit the number of byte
// to be read 
byte_s.mark(5);
System.out.println("ch3: " + ch3);
System.out.println("buff_str.reset(): ");
// Reset the position of the
// stream to the position last
// mark() method called
byte_s.reset();
// Read from the stread
char ch4 = (char) byte_s.read();
char ch5 = (char) byte_s.read();
// Display character
System.out.println("ch4: " + ch4);
System.out.println("ch5: " + ch5);
byte_s.close();
}
}

Output

輸出量

Left avail bytes = 4
ch1: a
ch2 : b
byte_s.mark(5):
ch3: b
buff_str.reset():
ch4: c
ch5: ?

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

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

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

相關文章

回文數猜想

問題描述: 一個正整數,如果從左向右讀(稱之為正序數)和從右向左讀(稱之為倒序數)是一樣的,這樣的數就叫回文數。任取一個正整數,如果不是回文數,將該數與他的倒序數相加…

文件上傳 帶進度條(多種風格)

文件上傳 帶進度條 多種風格 非常漂亮&#xff01; 友好的提示 以及上傳驗證&#xff01; 部分代碼&#xff1a; <form id"form1" runat"server"><asp:ScriptManager ID"scriptManager" runat"server" EnablePageMethods&quo…

同步---自旋鎖

1 自旋鎖的基本概念 自旋鎖最多只能被一個可執行線程持有&#xff0c;如果一個執行線程試圖獲得一個已經被使用的自旋鎖&#xff0c;那么該線程就會一直進行自旋&#xff0c;等待鎖重新可用。在任何時刻&#xff0c;自旋鎖都可以防止多余一個的執行線程同時進入臨界區。 Linu…

實習日志----4.播放時段參數設置

由于客戶在下發廣告時&#xff0c;一則廣告可在多個時段播放&#xff0c;這就需要設置多個播放時段的參數。 但在這種情況下&#xff0c;我并不知道用戶每次需要下發幾個時段&#xff0c;所以前臺不能設定死。 因此我要實現這么一個功能&#xff0c;讓用戶根據自己的需要來動態…

線性插值算法實現圖像_C程序實現插值搜索算法

線性插值算法實現圖像Problem: 問題&#xff1a; We are given an array arr[] with n elements and an element x to be searched amongst the elements of the array. 給定一個數組arr []&#xff0c;其中包含n個元素和一個要在該數組的元素中搜索的元素x 。 Solution: 解&…

hdu 1197

地址&#xff1a;http://acm.hdu.edu.cn/showproblem.php?pid1197 題意&#xff1a;求一個數轉換成10&#xff0c;12&#xff0c;16進制后各個位上的數的和是否相等。 mark&#xff1a;模擬進制轉換。 代碼&#xff1a; #include <stdio.h>int zh(int a, int n) {int su…

linux系統編程---線程總結

線程總結1 線程的實現線程創建線程退出線程等待線程清理2 線程的屬性線程的分離線程的棧地址線程棧大小線程的調度策略線程優先級3 線程的同步互斥鎖讀寫鎖條件變量信號量線程是系統獨立調度和分配的基本單位。同一進程中的多個線程將共享該進程中的全部系統資源&#xff0c;例…

博客上一些項目相關源碼鏈接

GitHub&#xff1a;https://github.com/beyondyanyu/Sayingyy

重新開啟Ctrl+Alt+Backspace快捷鍵

UBUNTU老用戶知道CtrlAltBackspace這個快捷鍵是用來快速重啟X的在9.04中被默認關閉了&#xff0c;那如何來打開它呢&#xff1f;在終端中輸入&#xff1a;sudo gedit /etc/X11/xorg.conf在其中加入&#xff1a;Section “ServerFlags”Option “DontZap” “false”EndSection退…

Java LocalDate類| 帶示例的getDayOfYear()方法

LocalDate類的getDayOfYear()方法 (LocalDate Class getDayOfYear() method) getDayOfYear() method is available in java.time package. getDayOfYear()方法在java.time包中可用。 getDayOfYear() method is used to get the day-of-year field value of this LocalDate obje…

火腿三明治定理

定理&#xff1a;任意給定一個火腿三明治&#xff0c;總有一刀能把它切開&#xff0c;使得火腿、奶酪和面包片恰好都被分成兩等份。 而且更有趣的是&#xff0c;這個定理的名字真的就叫做“火腿三明治定理”&#xff08;ham sandwich theorem&#xff09;。它是由數學家亞瑟?斯…

如何給Linux操作系統(CentOS 7為例)云服務器配置環境等一系列東西

1.首先&#xff0c;你得去購買一個云服務器&#xff08;這里以阿里云學生服務器為例&#xff0c;學生必須實名認證&#xff09; 打開阿里云&#xff0c;搜索學生服務器點擊進入即可 公網ip為連接云服務器的主機 自定義密碼為連接云服務器是需要輸入的密碼 購買即可 點擊云服…

Linux系統編程---I/O多路復用

文章目錄1 什么是IO多路復用2 解決什么問題說在前面I/O模型阻塞I/O非阻塞I/OIO多路復用信號驅動IO異步IO3 目前有哪些IO多路復用的方案解決方案總覽常見軟件的IO多路復用方案4 具體怎么用selectpollepolllevel-triggered and edge-triggered狀態變化通知(edge-triggered)模式下…

[轉帖]純屬娛樂——變形金剛vs天網

[轉帖]變形金剛2的影評-《變形金剛3 天網反擊戰》有一個問題困擾了我足足二十年&#xff1a;為什么汽車人要幫地球人&#xff1f;光用“所有有感知的生物都應享有自由”這個法則是根本說不過去的&#xff0c;因為豬也有感知&#xff0c;但人類就把豬圈養起來&#xff0c;隨意殺…

c#中textbox屬性_C#.Net中的TextBox.MaxLength屬性與示例

c#中textbox屬性Here we are demonstrating use of MaxLength property of TextBox. 在這里&#xff0c;我們演示了TextBox的MaxLength屬性的使用。 MaxLength property of TextBox is used to set maximum number of character that we can input into a TextBox. Limit of M…

IIS7 MVC網站生成、發布

(1)生成。 確保System.Web.Mvc.dll在bin目錄下 (2)發布網站到文件系統 (3)在IIS中為網站添加應用程序池&#xff08;一個虛擬目錄&#xff0c;一個應用程序池&#xff09; (4)添加在默認網站下添加虛擬目錄 &#xff08;5&#xff09;轉換為應用程序 至此&#xff0c;部署完畢 …

標題:明碼

轉載&#xff1a;https://blog.csdn.net/u011747888/article/details/79781040 標題&#xff1a;明碼 漢字的字形存在于字庫中&#xff0c;即便在今天&#xff0c;16點陣的字庫也仍然使用廣泛。 16點陣的字庫把每個漢字看成是16x16個像素信息。并把這些信息記錄在字節中。 一…

C語言多維數組

文章目錄多維數組數組名下標指向數組的指針作為函數參數的多維數組指針數組小結多維數組 如果某個數組的維數超過1&#xff0c;它就被稱為多維數組&#xff0c;例如&#xff0c;下面這個聲明&#xff1a; int matrix[6][10]創建了一個包含60個元素的矩陣。但是&#xff0c;它…

ubuntu路由器聯網_路由器及其協議簡介| 聯網

ubuntu路由器聯網路由器簡介 (Introduction to Router) Routers are network layer devices. Data on the network layer is known as packets. Routers work to forward packets from one network to another. Routers also maintain the address table. 路由器是網絡層設備。…

XPath學習:軸(5)——descendant-or-self

XPath 是一門在 XML 文檔中查找信息的語言。XPath 可用來在 XML 文檔中對元素和屬性進行遍歷。 XPath 是 W3C XSLT 標準的主要元素&#xff0c;并且 XQuery 和 XPointer 同時被構建于 XPath 表達之上。 推薦一個挺不錯的網站&#xff1a;http://www.zvon.org/xxl/XPathTutorial…