通过输入流来获取text文件内容,再返回输入流的内容
public String getStringFromInputStream(InputStream inputStream){
byte[] buffer=new byte[1024];
int hasRead=0;
//创建一个字节数组用于存储获取的text内的内容;
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();
}
本文介绍了一种通过输入流获取并返回文本文件内容的方法。该方法使用字节数组进行内容存储,并通过循环读取输入流直至读完所有内容。

2439

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



