Java FileInputStream available()方法與示例

FileInputStream類的available()方法 (FileInputStream Class available() method)

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

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

  • available() method is used to return the number of bytes left that can be read from this FileInputStream and without blocking by the next invocation of this method for this FileInputStream.

    available()方法用于返回可以從此FileInputStream讀取的剩余字節數,并且不會被此FileInputStream的下一次調用阻塞。

  • 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 while getting any input/output error or when this stream is closed by the close() method.

    IOException :在獲取任何輸入/輸出錯誤時或通過close()方法關閉此流時,可能引發此異常。

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 available bytes left that can be read from this FileInputStream during unblock.

方法的返回類型為int ,它返回在解除阻塞期間可以從此FileInputStream讀取的剩余可用字節數。

Example:

例:

// Java program to demonstrate the example 
// of int available() method 	
// of FileInputStream
import java.io.*;
public class AvailableOfFIS {
public static void main(String[] args) throws Exception {
FileInputStream fis_stm = null;
int count = 0;
try {
// Instantiates FileInputStream
fis_stm = new FileInputStream("D:\\includehelp.txt");
// Loop to read until available
// bytes left
while ((count = fis_stm.read()) != -1) {
// By using available() method is to
// return the available bytes to be read
int avail_bytes = fis_stm.available();
// Display corresponding bytes value
byte b = (byte) count;
// Display value of avail_bytes and b
System.out.print("fis_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 stream
if (fis_stm != null) {
fis_stm.close();
}
}
}
}

Output

輸出量

fis_stm.available(): 15 : byte: 0
fis_stm.available(): 14 : byte: 4
fis_stm.available(): 13 : byte: 74
fis_stm.available(): 12 : byte: 97
fis_stm.available(): 11 : byte: 118
fis_stm.available(): 10 : byte: 97
fis_stm.available(): 9 : byte: 0
fis_stm.available(): 8 : byte: 8
fis_stm.available(): 7 : byte: 87
fis_stm.available(): 6 : byte: 111
fis_stm.available(): 5 : byte: 114
fis_stm.available(): 4 : byte: 108
fis_stm.available(): 3 : byte: 100
fis_stm.available(): 2 : byte: 33
fis_stm.available(): 1 : byte: 33
fis_stm.available(): 0 : byte: 33

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

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

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

相關文章

mysql 輸出參數 sql語句_MySQL: 詳細的sql語句

1添1.1【插入單行】insert [into] (列名) values (列值)例:insert into Strdents (姓名,性別,出生日期) values (開心朋朋,男,1980/6/15)1.2【將現有表數據添加到一個已有表】insert into (列名) select from 例:insert into tongxunlu (姓名,地址,電子郵…

執行git push出現Everything up-to-date

在github上git clone一個項目,在里面創建一個目錄,然后git push的時候,出現報錯"Everything up-to-date" 原因:1)沒有git add .2)沒有git commit -m "提交信息"如果上面兩個步驟都成功…

Java File類boolean delete()方法(帶示例)

文件類布爾型delete() (File Class boolean delete()) This method is available in package java.io.File.delete(). 軟件包java.io.File.delete()中提供了此方法。 This method is used to delete file or directory by using delete() method and this method is accessible…

Unity3D Adam Demo的學習與研究

1.簡述 這篇文章是對Adam各種相關資料了解后進行一些精簡的內容。如果你想仔細研究某個技術請跳轉至unity相關頁面。 Adam官方頁面: https://unity3d.com/cn/pages/adam 搬運視頻以及資源包網盤下載: http://pan.baidu.com/s/1jH6NF86 Adam這個demo由8個人的團隊耗時6個月(part…

Java File類boolean isFile()方法(帶示例)

File類boolean isFile() (File Class boolean isFile()) This method is available in package java.io.File.isFile(). 軟件包java.io.File.isFile()中提供了此方法。 This method is used to check whether the file is specified by filepath is a file or not. 此方法用于檢…

要加油!

現實中我容易佩服一個人。 一個頑強的女人,一個艱苦奮斗的男人..... 但是在網絡的世界里,我沒有佩服過幾個,但是不得不說的就是冰河。同樣的年齡人家做的事情和我們做的事情差距是多么的大,真的想想心里都是天壤之別。 比一比才知…

Java DataOutputStream writeInt()方法及示例

DataOutputStream類writeInt()方法 (DataOutputStream Class writeInt() method) writeInt() method is available in java.io package. writeInt()方法在java.io包中可用。 writeInt() method is used to write the given integer value to the basic DataOutputStream as 4 b…

python安卓自動化實現方法_uiautomator +python 實現安卓UI自動化

簡單實例注:安卓6.0以上的手機不會自動安裝app-uiautomator.apk和app-uiautomator-test.apk,需要手動安裝,否則報錯ioerror RPC server not starteduiautomator pythonHTMLTestRunner 安卓UI自動化實現#coding:utf-8from uiautomator importD…

ES6特性之:Spread操作符

Spread操作符(...),也稱作展開操作符,作用是將可迭代的(Iterable)對象進行展開。 比如有2個數組,我們要將其中一個數組中所有元素插入到另一個數組中,通過Spread操作符,就可以這樣進行: var fruits ["…

Java類class isMemberClass()方法及示例

類的類isMemberClass()方法 (Class class isMemberClass() method) isMemberClass() method is available in java.lang package. isMemberClass()方法在java.lang包中可用。 isMemberClass() method is used to check whether the underlying class is a member class or not.…

velocity自定義函數_velocity基本語法和總結

一:基本語法:1、#set(#a "a")$a ##輸出語句時直接寫變量的名稱即可2、判斷語句:#if($a "a") ##判斷語句沒有括號,也是直接輸出$a3、數組:#set($arry [0..10])$foreach($i in $arry)$i ##換行#e…

docker-machine指定cpu個數

序 給本機的一個服務壓測,結果半天qps上不了萬,而且經常跑滿cpu,搞半天發現,docker里頭才1核1G內存。原來boot2docker默認給docker-machine分配1個cpu和1G內存。 修改配置 docker-machine create \--driver virtualbox \--virtual…

Java ClassLoader findResources()方法與示例

ClassLoader類findResources()方法 (ClassLoader Class findResources() method) findResources() method is available in java.lang package. findResources()方法在java.lang包中可用。 findResources() method is used to find all the resources with the given resource …

Java ByteArrayInputStream mark()方法與示例

ByteArrayInputStream類mark()方法 (ByteArrayInputStream Class mark() method) mark() method is available in java.util package. mark()方法在java.util包中可用。 mark() method is used to set the current mark position in the stream from where read or write can b…

java mediainfo.dll_MediaInfo庫的簡單使用

想到一個問題, 如何獲得一個圖像文件(比如jpg, bmp, png)的信息. 自己查查文件的格式, 寫一個解析, 應該不困難; 但是找了下現成的, 發現MediaInfo庫已經可以非常好的實現需要的功能了.MediaInfo可以在sourceforge上找到, 是一個解析視頻,音頻, 圖片等媒體文件的庫. 可以得到文…

Redis配置和常用命令

1 redis.conf配置文件:2 引用3 #是否作為守護進程運行4 daemonize yes5 #配置pid的存放路徑及文件名,默認為當前路徑下6 pidfile redis.pid7 #Redis默認監聽端口8 port 63799 #客戶端閑置多少秒后,斷開連接 10 timeout 300 11 #日志顯示級別 …

oracle中dbms_DBMS中的功能依賴性和屬性關閉

oracle中dbms功能依賴 (Functional Dependency) A relational Database management System (RDBMS) represents the database o a collection of relations/tables. A functional dependency is a constraint between two sets of attributes in a relation. It is the propert…

java invoke 泛型_利用Java反射機制和泛型,全自動解析json

有啦這個簡直,太爽啦,利用Java 反射機制,利用Class 就可以得到 類的 變量 Field[] fieldscls.getDeclaredFields();還可以通過類中 的方法名字 去執行這個方法m1 cls.getDeclaredMethod(getMothodName(fields[j].getName()), String.class)…

2_C語言中的數據類型 (四)整數與無符號數

1.1 sizeof關鍵字 sizeof是c語言關鍵字,功能是求指定數據類型在內存中的大小,單位:字節 sizeof與size_t類型 1.1 int類型 1.1.1 int常量,變量 int就是32位的一個二進制整數,在內存當中占據4個字節…

python 示例_Python TextCalendar類別| pryear()方法與示例

python 示例Python TextCalendar.pryear()方法 (Python TextCalendar.pryear() Method) pryear() method is an inbuilt method of the TextCalendar class of calendar module in Python. It works on text calendars. It uses an instance of TextCalendar class and prints …