1、 //得到cache的路径
public String getDiskCachePath(Context context){
if(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())||!Environment.isExternalStorageRemovable())
{
//如果sd卡存在并且sd卡没有移除,返回外部的cache
return context.getExternalCacheDir().getPath();
}else
{//返回内部的cache
return context.getCacheDir().getPath();
}
}
//解析的json串存入cache
//得到路径
String cachePath = getDiskCachePath(MainActivity.this);
System.out.println("========" + cachePath);
//存入数据
File file = new File(cachePath + "/json");
OutputStream os = new FileOutputStream(file);
os.write(s.getBytes());
os.flush();