用數組讀文件的問題
JAVA 的IO流 4-2中
while((bytes=in.read(buf, 0, buf.length))!=-1),byte返回的應該是讀到的字節個數,它永遠不會是-1吧,這位什么用這個做條件,不應該是一個buf[i]!=-1嗎,請大神解惑.
JAVA 的IO流 4-2中
while((bytes=in.read(buf, 0, buf.length))!=-1),byte返回的應該是讀到的字節個數,它永遠不會是-1吧,這位什么用這個做條件,不應該是一個buf[i]!=-1嗎,請大神解惑.
2017-07-11
舉報
2017-07-11
看API文檔的解釋,the total number of bytes read into the buffer, or -1 if there is no more data because the end of the file has been reached.讀到數據字節個數,如果沒有讀到數據時,返回-1