首页 > 其他分享 >将assets or raw folder文件复制到sd卡

将assets or raw folder文件复制到sd卡

时间:2023-06-20 18:06:41浏览次数:43  
标签:复制到 files assets int fileName raw compareTo new out


有时候我们需要把程序的raw文件放在sd卡中,其实有时候这样做可以释放资源,有时候可能是使坏呼呼

void copyAssets() 
{ 
    String[] files; 
    try 
    { 
        files = this.getResources().getAssets().list(""); 
    } 
    catch (IOException e1) 
    { 
        return; 
    } 
 
    if(!mWorkingPath.exists()) 
    { 
        if(!mWorkingPath.mkdirs()) 
        { 
            new AlertDialog.Builder(this) 
                .setTitle(R.string.ERROR) 
                .setMessage(R.string.FAILED_DIR_CREATE) 
                .setPositiveButton(android.R.string.ok, new OnClickListener(){ 
                    @Override 
                    public void onClick(DialogInterface dialog, int which) 
                    { 
                        dialog.dismiss(); 
                    } 
                }) 
                .create() 
                .show(); 
        } 
    } 
 
    for(int i = 0; i < files.length; i++) 
    { 
        try 
        { 
            String fileName = files[i]; 
 
            if(fileName.compareTo("images") == 0 || 
               fileName.compareTo("sounds") == 0 || 
               fileName.compareTo("webkit") == 0) 
            { 
                continue; 
            } 
 
            File outFile = new File(mWorkingPath, fileName); 
            if(outFile.exists()) continue; 
 
            InputStream in = getAssets().open(fileName); 
            OutputStream out = new FileOutputStream(outFile); 
 
            // Transfer bytes from in to out 
            byte[] buf = new byte[1024]; 
            int len; 
            while ((len = in.read(buf)) > 0) 
            { 
                out.write(buf, 0, len); 
            } 
 
            in.close(); 
            out.close(); 
        } 
        catch (FileNotFoundException e) 
        { 
            e.printStackTrace(); 
        } 
        catch (IOException e) 
        { 
            e.printStackTrace(); 
        } 
    }

 

标签:复制到,files,assets,int,fileName,raw,compareTo,new,out
From: https://blog.51cto.com/u_16166892/6523988

相关文章

  • MapView Overlay Drawable 的使用
    packageorg.yexing.mapdemos;GraphicOverlay.javaimportandroid.graphics.Canvas;//importandroid.graphics.Paint;//importandroid.graphics.RectF;importandroid.graphics.drawable.BitmapDrawable;importandroid.graphics.drawable.Drawable;impor......
  • vue3+vite 动态引用静态资源,动态引入assets文件夹图片的几种方式
    可以参考这个回答,亲测有用 https://blog.csdn.net/weixin_43743175/article/details/125892613 ......
  • python: draw
     #-*-coding:utf-8-*-#pipinstallpygame"""DrawTool.py画板"""importmathimportpygamefrompygame.localsimportQUIT,KEYDOWN,K_ESCAPE,MOUSEBUTTONDOWN,MOUSEMOTION,MOUSEBUTTONUP#导入事件classBrush(object):......
  • 百度地图 鼠标绘制库 bmap-draw 避坑
    1.距离测量工具无法修改单位为米根据官方文档:距离测量类unit string 测量所用单位制,默认为千米'kilometers',另外可接受米'metric'无法对其进行修改this.distance=newDistanceMeasure(scene,{unit:"metric",isSeries,//不连续测量...m......
  • 在APK打包过程中,Assets资源漏编译漏打包的本质
    背景作为Androider,我们平时在Assets资源目录下都放点啥呢,字体、预置数据、图片、配置文件…等等,那大家有没有想过,万一哪天我在Assets目录下新增了一个子目录放了点自己的资源文件,打包之后再解包发现Apk包里没有找到这部分文件,怎么办呢?原理分析我们都知道典型的Android应用......
  • Draw.io部署教程
    Draw.io是GitHub上的一个开源的免费流程图绘制工具,功能非常的丰富,使用上和ProcessOn基本上是一致的,但是ProcessOn是收费的。 Draw.io也有在线网页版,可以直接访问(https://www.draw.io/)进行使用。也有桌面版,桌面版下载地址:https://github.com/jgraph/drawio-desktop/releases。不管......
  • Capture One 23 Pro mac(RAW转换和图像编辑工具)
    CaptureOne23ProMac版是一款专业的RAW转换和图像编辑软件,有了它,您可以快速方便地将数字图像转换成数码照片和视频。CaptureOne23ProMac版的RAW格式转换功能使用专业的图像处理技术,帮助您将原始视频、照片或3D文件转换为RAW格式,使您可以轻松编辑。此外,您可以将原始视频......
  • unity将安卓streamingAssetsPath文件复制到persistentDataPath
    privatevoidTestCopy(){stringfrom=Application.streamingAssetsPath+"/Test/test.txt";stringto=Application.persistentDataPath+"/Test/";CopyFile(from,to);}publicstaticvoidCopyFile(stringsourcePath,stringdesti......
  • rawNode的成员变更用例
    【用例内容】 【主要逻辑】applyConfChange的时候1)通过之前的changer类做检查2)替换cfg和prs为新的值......
  • post、raw、json调用第三方接口
    1、调用第三方接口,对方接口文档写到”请求方式postjson格式、请求参数json格式“,看不懂,就用postMan试试看。发现只有一种方式能调用通, 2、 3、Content-Type:application/json  4、根据上面的方式,所有写了下面的方法:/****@paramurl接口地址*@paramputData......