gpt4 book ai didi

java - BufferedInputStream 到字符串的转换?

转载 作者:IT老高 更新时间:2023-10-28 20:29:51 26 4
gpt4 key购买 nike

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

您好,我想将此 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);

关于java - BufferedInputStream 到字符串的转换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5713857/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com