BufferedInputStream字符串转换?

可能重复:
在Java中,如何将InputStream读取/转换为字符串?

您好,我想把这个BufferedInputStream放入我的字符串中,我该怎么做?

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);

番石榴:

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

与Commons / IO:

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

我建议你使用apache commons IOUtils

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

上一篇: BufferedInputStream To String Conversion?

下一篇: Recursively counting files in a Linux directory