BufferedInputStream To String Conversion?

Possible Duplicate:
In Java how do a read/convert an InputStream in to a string?

Hi I want to put this BufferedInputStream into my string how can I do this?

BufferedInputStream in = new BufferedInputStream(sktClient.getInputStream() );
String a= in.read();

BufferedInputStream in = new BufferedInputStream(sktClient.getInputStream());
byte[] contents = new byte[1024];

int bytesRead = 0;
String strFileContents; 
while((bytesRead = in.read(contents)) != -1) { 
    strFileContents += new String(contents, 0, bytesRead);              
}

System.out.print(strFileContents);

With Guava:

new String(ByteStreams.toByteArray(inputStream),Charsets.UTF_8);

With Commons / IO:

IOUtils.toString(inputStream, "UTF-8")

我建议你使用apache commons IOUtils

String text = IOUtils.toString(sktClient.getInputStream());
链接地址: http://www.djcxy.com/p/13724.html

上一篇: 从InputStream中读取文本

下一篇: BufferedInputStream字符串转换?