Android中如何引入text文件

通过获取输入流来读取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();
}

猜你喜欢

转载自blog.csdn.net/gooddai/article/details/53006871