通过获取输入流来读取text文件的内容,再返回一个该内容:
public String getStringFromInputStream(InputStream inputStream){
byte[] buffer=new byte[1024];int hasRead=0;
StringBuilder result=new StringBuilder("");
try{
while((hasRead=inputStream.read(buffer))!=-1){
result.append(new String(buffer,0,hasRead,"GBK"));
}
}catch(Exception e){
e.printStackTrace();
}
return result.toString();
}
本文介绍了一种从输入流中读取文本文件内容的方法,并将其转换为字符串形式返回。此过程涉及逐块读取文件内容并拼接成完整的字符串。

1137

被折叠的 条评论
为什么被折叠?



