課程
/后端開(kāi)發(fā)
/Java
/文件傳輸基礎(chǔ)——Java IO流
我這樣理解的,數(shù)組里面最后一個(gè)的索引是-1,所以讀到-1就結(jié)束了,可是不知道為什么又轉(zhuǎn)換成16進(jìn)制了,b輸出來(lái)到底是什么內(nèi)容?
2018-08-26
源自:文件傳輸基礎(chǔ)——Java IO流 4-1
正在回答
int b;
while((b=in.read())!=-1){
}
這里定義的b 是in.read()讀到有值的話就是整數(shù),并把值賦值給b,然后與-1做比較,不等于-1,說(shuō)明還有值,可以繼續(xù)讀取,如果是-1,里面沒(méi)有值了,退出循環(huán)
?/**
? ? ?* 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();
? ? }
?說(shuō)的很清楚,the next byte of data, or <code>-1</code> if the end of the
? ? ?*? ? ? ? ? ? ?file is reached.沒(méi)有值是-1,讀的是里面的數(shù)據(jù),不是索引
你可以去看看源碼,里面表示read方法的返回值,源碼里面有寫如果沒(méi)有結(jié)尾,輸出值就不為-1
舉報(bào)
為您介紹IO流的使用,以及對(duì)象的序列化和反序列化的內(nèi)容
2 回答out.write(buf, 0, b);//這個(gè)b什么意思?寫b個(gè)長(zhǎng)度的字節(jié)嗎?但是沒(méi)有給b賦值啊
1 回答bytes是什么含義,表示讀到的數(shù)據(jù)的大小嗎?還是讀到的數(shù)據(jù)長(zhǎng)度?
2 回答在源碼中進(jìn)行搜索的快捷鍵是什么??
2 回答0xf在if中代表什么
4 回答String file = "demo/dos.dat"是創(chuàng)建還是什么?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2018-10-19
int b;
while((b=in.read())!=-1){
}
這里定義的b 是in.read()讀到有值的話就是整數(shù),并把值賦值給b,然后與-1做比較,不等于-1,說(shuō)明還有值,可以繼續(xù)讀取,如果是-1,里面沒(méi)有值了,退出循環(huán)
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();
? ? }
?說(shuō)的很清楚,the next byte of data, or <code>-1</code> if the end of the
? ? ?*? ? ? ? ? ? ?file is reached.沒(méi)有值是-1,讀的是里面的數(shù)據(jù),不是索引
2018-08-27
你可以去看看源碼,里面表示read方法的返回值,源碼里面有寫如果沒(méi)有結(jié)尾,輸出值就不為-1