用數(shù)組讀文件的問題
JAVA 的IO流 4-2中
while((bytes=in.read(buf, 0, buf.length))!=-1),byte返回的應(yīng)該是讀到的字節(jié)個數(shù),它永遠(yuǎn)不會是-1吧,這位什么用這個做條件,不應(yīng)該是一個buf[i]!=-1嗎,請大神解惑.
JAVA 的IO流 4-2中
while((bytes=in.read(buf, 0, buf.length))!=-1),byte返回的應(yīng)該是讀到的字節(jié)個數(shù),它永遠(yuǎn)不會是-1吧,這位什么用這個做條件,不應(yīng)該是一個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.讀到數(shù)據(jù)字節(jié)個數(shù),如果沒有讀到數(shù)據(jù)時,返回-1