//加载本地缓存
private String okGetBenDiRequse(String path) throws Exception {
//此文件已经存在
File file = new File(path,"json.txt");
//文件读取流(输入流)
FileInputStream inputStream = new FileInputStream(file);
//这个类是android 中的类
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte [] bytes = new byte[1024];
int len=0;
while ((len=inputStream.read(bytes))!=-1){
outputStream.write(bytes,0,len);
}
//不要忘记关流哦,注意关流顺序
outputStream.close();
inputStream.close();
return outputStream.toString();
}
//缓存
private void writeJsonToFile(InputStream stream) throws IOException {
//将数据写到文件中
File file = new File(cachedirectory);
file.mkdirs();
File file1 = new File(file,"json.txt");
file1.createNewFile();
FileOutputStream outputStream = new FileOutputStream(file1);
byte [] bytes = new byte[1024];
int len=0;
while ((len=stream.read(bytes))!=-1){
outputStream.write(bytes,0,len);
}
outputStream.close();
stream.close();
}