課程
/后端開發
/Java
/文件傳輸基礎——Java IO流
我這樣理解的,數組里面最后一個的索引是-1,所以讀到-1就結束了,可是不知道為什么又轉換成16進制了,b輸出來到底是什么內容?
2018-08-26
源自:文件傳輸基礎——Java IO流 4-1
正在回答
int b;
while((b=in.read())!=-1){
}
這里定義的b 是in.read()讀到有值的話就是整數,并把值賦值給b,然后與-1做比較,不等于-1,說明還有值,可以繼續讀取,如果是-1,里面沒有值了,退出循環
?/**
? ? ?* Reads a byte of data from this input stream. This method blocks
? ? ?* if no input is yet available.
? ? ?*
? ? ?* @return? ? ?the next byte of data, or <code>-1</code> if the end of the
? ? ?*? ? ? ? ? ? ?file is reached.
? ? ?* @exception? IOException? if an I/O error occurs.
? ? ?*/
? ? public int read() throws IOException {
? ? ? ? return read0();
? ? }
?說的很清楚,the next byte of data, or <code>-1</code> if the end of the
? ? ?*? ? ? ? ? ? ?file is reached.沒有值是-1,讀的是里面的數據,不是索引
你可以去看看源碼,里面表示read方法的返回值,源碼里面有寫如果沒有結尾,輸出值就不為-1
舉報
為您介紹IO流的使用,以及對象的序列化和反序列化的內容
2 回答out.write(buf, 0, b);//這個b什么意思?寫b個長度的字節嗎?但是沒有給b賦值啊
1 回答bytes是什么含義,表示讀到的數據的大小嗎?還是讀到的數據長度?
2 回答在源碼中進行搜索的快捷鍵是什么??
2 回答0xf在if中代表什么
4 回答String file = "demo/dos.dat"是創建還是什么?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2018-10-19
int b;
while((b=in.read())!=-1){
}
這里定義的b 是in.read()讀到有值的話就是整數,并把值賦值給b,然后與-1做比較,不等于-1,說明還有值,可以繼續讀取,如果是-1,里面沒有值了,退出循環
2018-10-25
?/**
? ? ?* Reads a byte of data from this input stream. This method blocks
? ? ?* if no input is yet available.
? ? ?*
? ? ?* @return? ? ?the next byte of data, or <code>-1</code> if the end of the
? ? ?*? ? ? ? ? ? ?file is reached.
? ? ?* @exception? IOException? if an I/O error occurs.
? ? ?*/
? ? public int read() throws IOException {
? ? ? ? return read0();
? ? }
?說的很清楚,the next byte of data, or <code>-1</code> if the end of the
? ? ?*? ? ? ? ? ? ?file is reached.沒有值是-1,讀的是里面的數據,不是索引
2018-08-27
你可以去看看源碼,里面表示read方法的返回值,源碼里面有寫如果沒有結尾,輸出值就不為-1