第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

為什么打印這個(gè)c出現(xiàn)的是整個(gè)文本內(nèi)容,c不是read返回的讀取的總個(gè)數(shù)嗎?

int?c?=?0;
while((c=isr.read())!=-1){
????System.out.print((char)c);//為什么可以打印c?C難不道不是代表讀取的數(shù)量只是一個(gè)計(jì)數(shù)功能???


正在回答

4 回答

?c表示當(dāng)前讀取到的字節(jié) 。

1、

c = isr.read() ? ?Reads a single character ?讀取單個(gè)character

the next byte of data, or -1 if the end of the file is reached

返回下一個(gè)next byte of data

2、

c = isr.read(byte[] , start,len)?Reads characters into a portion of an array 讀取多個(gè)charachters?

返回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.

? 返回total所有的number,也就數(shù)量


The character read, or -1 if the end of the stream has been reached

? ? ? 如果流讀取結(jié)束,將返回-1

The number of characters read, or -1 if the end of the stream has been reached ?

? ? 如果流讀取結(jié)束,返回-1

所以read()不是表示讀取的計(jì)數(shù),或者位置,表示下一個(gè)byte.


/****************************************常用用法


byte[] b = new byte[8 * 1024];// 8kb

// System.out.println(b.length);

// new byte

int a = 0;

FileOutputStream out = new FileOutputStream(destfile);

while ((a = in.read(b, 0, b.length)) != -1) {

out.write(b, 0, a);

out.flush();// 最好加上

這里的a表示總共。total的計(jì)數(shù)。

? ?可以看下out.write(b,off,len);的講解

Writes len bytes from the specified byte array starting at offset off to this file output stream.

? 從off位置開始,從流讀取長(zhǎng)度為lend的byte到b里面

Overrides: write(...) in OutputStream

Parameters:

b the data. 數(shù)據(jù)

off the start offset in the data. 從b的start位置開始

len the number of bytes to write. 讀取長(zhǎng)度為len的byte數(shù)據(jù) ,也就是返回的in.read(b,0,b.length)

}


0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

糖醋肉3984350 提問者

我這么理解,也就是說單個(gè)字符的時(shí)候表示讀取的下一個(gè)字符,用數(shù)組緩沖讀取多個(gè)時(shí),代表總數(shù)嘛?
2016-10-14 回復(fù) 有任何疑惑可以回復(fù)我~
#2

張博

兩個(gè)不一樣,你可以看看那個(gè)英語(yǔ)翻譯。
2016-10-15 回復(fù) 有任何疑惑可以回復(fù)我~
int?c?=?0;
while((c=isr.read())!=-1){?.?
????System.out.print((char)c);

// 首先這里按照字符流讀取,即讀到的是Unicode編碼的字符;

2.

“向上兼容”--即:不同數(shù)據(jù)類型的數(shù)據(jù)參與運(yùn)算,數(shù)據(jù)類型要強(qiáng)制轉(zhuǎn)換,轉(zhuǎn)換的方向是

(unsigned)char,(unsigned)short->int->unsigned->long->unsigned long->float->double->longdouble。

3.不管C定義是char還是int ,它都是作為一個(gè)容器來存儲(chǔ)讀到的數(shù)據(jù)

the next byte of data, or -1 if the end of the file is reached;若讀完結(jié)束返回-1,而不是計(jì)數(shù);

4: 在定義C 容器時(shí)候,因?yàn)椤跋蛏霞嫒荨焙妥詈笠祷?1來說;定義為int 最合適;輸出時(shí),則需要強(qiáng)制類型轉(zhuǎn)換;

5: 區(qū)別:

int?c?=?read();???//?存入C容器中,結(jié)束返回-1;
int?c?=?read(byte,star,length);???//計(jì)數(shù),結(jié)束返回-1;


1 回復(fù) 有任何疑惑可以回復(fù)我~

看清楚兩個(gè)方法是不一樣的好伐!無參數(shù)的read()方法是每次讀取一個(gè)char字符,有參數(shù)的read(buffer, 0, buffer.length)是將讀取的內(nèi)容先放到buffer中去,而返回的是每次讀取的char字符個(gè)數(shù)!

1 回復(fù) 有任何疑惑可以回復(fù)我~
#1

糖醋肉3984350 提問者

嗯嗯!!謝謝旁友!你這么一說我就理解了
2016-10-23 回復(fù) 有任何疑惑可以回復(fù)我~

因?yàn)閖ava的文本(char)本來就是一個(gè)16位無符號(hào)的整數(shù),通過強(qiáng)轉(zhuǎn)(char)c之后,java就會(huì)將返回的整數(shù)轉(zhuǎn)換成char,因?yàn)橥ㄟ^read()的方法獲取的就是char類型數(shù)據(jù),只不過是用整數(shù)形式去表示了,所以可以打印的 是文本內(nèi)容

1 回復(fù) 有任何疑惑可以回復(fù)我~
#1

糖醋肉3984350 提問者

我記得老師說,c代表總個(gè)數(shù),所以我就有點(diǎn)蒙了。既然是個(gè)數(shù)又怎么強(qiáng)轉(zhuǎn)成文本呢。。。
2016-10-14 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

為什么打印這個(gè)c出現(xiàn)的是整個(gè)文本內(nèi)容,c不是read返回的讀取的總個(gè)數(shù)嗎?

我要回答 關(guān)注問題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)