如何將BufferedReader
中的read()
返回的整數轉換爲實際的字符值,然後將其附加到字符串? read()
返回表示讀取字符的整數。當我這樣做時,它不會將實際字符附加到字符串中。相反,它將整數表示本身附加到String。獲取由BufferedReader中的read()返回的字符
int c;
String result = "";
while ((c = bufferedReader.read()) != -1) {
//Since c is an integer, how can I get the value read by incoming.read() from here?
response += c; //This appends the integer read from incoming.read() to the String. I wanted the character read, not the integer representation
}
我應該怎麼做來獲取實際數據?
感謝非常明確的答案更高效! – Fattie
@JoeBlow感謝您的評論。關於你的編輯,我覺得關閉讀者是誰創造讀者的責任。因爲我們沒有看到讀者的創作,關閉它在這裏是不適當的,超出了答案的範圍。 – ILMTitan