Java LineNumberInputStream available()方法与示例
LineNumberInputStream類的available()方法 (LineNumberInputStream Class available() method)
available() method is available in java.io package.
available()方法在java.io包中可用。
available() method is used to return the number of available bytes that can be read from this LineNumberInputStream.
available()方法用于返回可從此LineNumberInputStream讀取的可用字節數。
available() 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.
available()方法是一種非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。
available() method may throw an exception at the time of returning available bytes.
available()方法在返回可用字節時可能會引發異常。
IOException: This exception may throw when getting any input/output error while performing.
IOException :在執行過程中遇到任何輸入/輸出錯誤時,可能引發此異常。
Syntax:
句法:
public int available();Parameter(s):
參數:
It does not accept any parameter.
它不接受任何參數。
Return value:
返回值:
The return type of the method is int, it returns the number of bytes left that can be read from this LineNumberInputStream without blocking.
方法的返回類型為int ,它返回可以從此LineNumberInputStream讀取而不會阻塞的剩余字節數。
Example:
例:
// Java program to demonstrate the example // of int available() method of // LineNumberInputStreamimport java.io.*;public class AvailableOfLNIS {public static void main(String[] args) throws Exception {FileInputStream fis_stm = null;LineNumberInputStream line_stm = null;int val = 0;try {// Instantiates FileInputStreamfis_stm = new FileInputStream("D:\\includehelp.txt");line_stm = new LineNumberInputStream(fis_stm);// Loop to read until available// bytes leftwhile ((val = fis_stm.read()) != -1) {// By using available() method is to// return the available bytes to be readint avail_bytes = line_stm.available();// Display corresponding byte valuebyte b = (byte) val;// Display value of avail_bytes and bSystem.out.print("line_stm.available(): " + avail_bytes);System.out.println(" : " + "byte: " + b);}} catch (Exception ex) {System.out.println(ex.toString());} finally {// with the help of this block is to// free all necessary resources linked// with the streamif (fis_stm != null) {fis_stm.close();if (line_stm != null) {line_stm.close();}}}} }Output
輸出量
line_stm.available(): 1 : byte: 74 line_stm.available(): 1 : byte: 65 line_stm.available(): 0 : byte: 86 line_stm.available(): 0 : byte: 65翻譯自: https://www.includehelp.com/java/linenumberinputstream-available-method-with-example.aspx
總結
以上是生活随笔為你收集整理的Java LineNumberInputStream available()方法与示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何在python中获取浮点数的十六进制
- 下一篇: python中的Lambda表达式/函数