The invention involves a method of batch copying of Assets files, which is pre configured through the resource.xml configuration file for the path of the file under the Assets directory, reads the resource.xml file by using the AssetsManager.open interface, gets the path of the target file, and then calls the AssetsManager.open interface to read the target file. Compared with the existing technology, the batch copying method of the invention greatly improves the speed of batch copying.
【技术实现步骤摘要】
Assets文件批量拷贝方法
本专利技术涉及Android应用
,具体涉及一种Assets文件批量拷贝方法。
技术介绍
Assets,为Android应用内存放资源文件的目录。AssetsManager,为Android内的一个可以操作Assets目录的资源管理类,它含有list和open等接口,list接口可以获取Assets目录下的文件夹路径,open接口可以打开Assets目录下指定的文件。Sdcard,为Android手机存储内存卡。如图1所示,需要将assets/config目录下的所有文件拷贝到sdcard下,已有的解决方案是通过AssetsManager.list(“config”)接口遍历config目录下的所有文件夹和文件,如果遍历获取到的是文件,则调用AssetsManager.open读取文件进行拷贝;如果获取到是文件夹,那么则需要再次调用list接口进行遍历获取,需要调用AssetsManager.list(“config/data”)和AssetsManager.list(“config/resource”),如果存在的文件夹层次越多调用list的次数越多。现有的方案通过调用AssetsManager.list接口来遍历文件的,而该接口调用比较耗时,平均耗时在20毫秒~200毫秒,根据机子性能不同存在差异。所以现有方案存在的缺点就是如果存在文件夹层次较多的情况下,需要多次调用AssetsManager.list接口,导致非常耗时,使用不当甚至会发生ANR,ANR(ApplicationNotResponding)指的是应用程 ...
【技术保护点】
1.一种Assets文件批量拷贝方法,其特征在于:所述批量拷贝方法包括以下步骤:步骤1、在Assets目录下创建resouces.xml配置文件,该文件的内容即为Assets目录下的文件路径配置;步骤2、调用AssetsManager.open(“resources.xml”)读取resource.xml配置文件,并解析resources.xml文件,获取Assets目录下的文件路径,即目标文件路径;步骤3、根据步骤2中得到的目标文件路径,调用AssetsManager.open读取目标文件,并将目标文件拷贝到sdcard中。
【技术特征摘要】
1.一种Assets文件批量拷贝方法,其特征在于:所述批量拷贝方法包括以下步骤:步骤1、在Assets目录下创建resouces.xml配置文件,该文件的内容即为Assets目录下的文件路径配置;步骤2、调用AssetsManager.open(“resources...
【专利技术属性】
技术研发人员:黄桂生,郑光暖,李晓伟,
申请(专利权)人:厦门亿联网络技术股份有限公司,
类型:发明
国别省市:福建,35
还没有人留言评论。发表了对其他浏览者有用的留言会获得科技券。