迷你世界远古黑龙打法攻略 远古黑龙怎么打

迷你世界...

?舒 颜 ...o° ?舒 颜 ...o°
回答
  • 卤蛋 卤蛋

    安卓开发中设置文件缓存的方法,参考代码如下:
    1 public class configcache {
    2 private static final string tag=configcache.class.getname();3
    4 public static final int config_cache_mobile_timeout=3600000;1 hour
    5 public static final int config_cache_wifi_timeout=300000;5 minute
    6
    7 public static string geturlcache(string url){
    8 if(url=**){
    9 return **;10 }
    11
    12 string result=**;13 file file=new file(appapplication.msdcarddatadir+"/"+getcachedecodestring(url));14 if(file.ex**ts()&file.**file()){
    15 long expiredtime=system.currenttimemill**()-file.lastmodified();16 log.d(tag,file.getabsolutepath()+"expiredtime:"+expiredtime/60000+"min");17/1.in case the system time ** incorrect(the time ** turn back long ago)
    18/2.when the network ** invalid,you can only read the cache
    19 if(appapplication.mnetworkstate!networkutils.networn_none&expiredtime){
    20 return **;21 }
    22 if(appapplication.mnetworkstate=networkutils.networn_wifi
    23&expiredtime>config_cache_wifi_timeout){
    24 return **;25 } else if(appapplication.mnetworkstate=networkutils.networn_mobile
    26&expiredtime>config_cache_mobile_timeout){
    27 return **;28 }
    29 try {
    30 result=fileutils.readtextfile(file);31 } catch(ioexception e){
    32 e.printstacktrace();33 }
    34 }
    35 return result;36 }
    37
    38 public static void seturlcache(string data,string url){
    39 file file=new file(appapplication.msdcarddatadir+"/"+getcachedecodestring(url));40 try {
    41/创建缓存数据到磁盘,就是创建文件
    42 fileutils.writetextfile(file,data);43 } catch(ioexception e){
    44 log.d(tag,"write"+file.getabsolutepath()+"data failed!45 e.printstacktrace();46 }
    47 }
    48
    49 public static string getcachedecodestring(string url){
    50/1.处理特殊字符
    51/2.去除后缀名带来的文件浏览器的视图凌乱(特别是图片更需要如此类似处理,否则有的手机打开图库,全是我们的缓存图片)
    52 if(url!**){
    53 return url.replaceall("[.:/,%?.replaceall("[+]+","+");54 }
    55 return **;56 }
    57 }
    58
    59
    上面的方法如何调用,参考代码如下:
    1 void getconfig(){
    2/首先尝试读取缓存
    3 string cacheconfigstring=configcache.geturlcache(config_url);4/根据结果判定是读取缓存,还是重新读取
    5 if(cacheconfigstring!**){
    6 showconfig(cacheconfigstring);7 } else {
    8/如果缓存结果是空,说明需要重新加载
    9/缓存为空的原因可能是1.无缓存;2.缓存过期;3.读取缓存出错
    10 asynchttpclient client=new asynchttpclient();11 client.get(config_url,new asynchttpresponsehandler(){
    12@override
    13 public void onsuccess(string result){
    14/成功下载,则保存到本地作为后面缓存文件
    15 configcache.seturlcache(result,config_url);16/后面可以是ui更新,仅供参考
    17 showconfig(result);18 }
    19@override
    20 public void onfailure(throwable arg0){
    21/根据失败原因,考虑是显示加载失败,还是再读取缓存
    22 }
    23 });24 }
    25 }
    26
    27

类似问答
精品推荐

友情链接

友链互换QQ:

谷财 备案编号:蜀ICP备11019336号-3商务合作:235-677-2621

Copyright 2009-2020 Chengdu Sanzilewan Technology Co.,Ltd all rights reserve

抵制不良游戏 拒绝盗版游戏 注意自我保护 谨防受骗上当 适度游戏益脑 沉迷游戏伤身 合理安排时间 享受健康生活