日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

fileinputstream_从Java中的FileInputStream读取字节

發布時間:2024/7/5 java 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 fileinputstream_从Java中的FileInputStream读取字节 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

以下示例顯示了如何從Java中的FileInputStream讀取字節。

import java.io.File;import java.io.FileInputStream;public class fileInputStream {

public static void main(String[] args) {

byte[] data = new byte[1024]; //allocates memory for 1024 bytes

//be careful about how to declare an array in Java

int readBytes;

try {

File file = new File("testfile");

file.createNewFile();

FileInputStream in = new FileInputStream(file);

while ((readBytes = in.read(data)) != -1) {

//read(byte[] b)

//Reads some number of bytes from the input stream and stores them into the buffer array b.

System.out.println("read " + readBytes + " bytes, and placed them into temp array named data");

System.out.println("data :" + data[123]);

}

in.close();

} catch (Exception e) {

e.printStackTrace();

}

}}

如果放置一些數據,它將給出以下輸出:

run:
read 1024 bytes, and placed them into temp array named data
read 1024 bytes, and placed them into temp array named data
read 1024 bytes, and placed them into temp array named data
read 1024 bytes, and placed them into temp array named data
read 1024 bytes, and placed them into temp array named data
read 1024 bytes, and placed them into temp array named data
read 952 bytes, and placed them into temp array named data
BUILD SUCCESSFUL (total time: 2 seconds)

最后,開發這么多年我也總結了一套學習Java的資料與面試題,如果你在技術上面想提升自己的話,可以關注我,私信發送領取資料或者在評論區留下自己的聯系方式,有時間記得幫我點下轉發讓跟多的人看到哦。

總結

以上是生活随笔為你收集整理的fileinputstream_从Java中的FileInputStream读取字节的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。