android APP源码预置文件并拷贝到应用files文件夹下

本文介绍了一种从Android应用的assets文件夹中复制文件到应用内部存储的方法。通过使用InputStream和OutputStream,能够将特定的二进制文件(如file123.bin)从assets资源文件夹复制到应用的文件目录下,以便于进一步处理或运行时使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

file123.bin文件预置进assets文件夹下

	copyMcuFile("file123.bin", new File(getFilesDir()+ "/file123.bin"));

    private void copyMcuFile(String sourceFileName, File dest) throws IOException {
        InputStream in = null;
        OutputStream out = null;
        final int READ_BUFFER_SIZE = 4 * 1024 * 1024;
        try {
            in = getAssets().open(sourceFileName);
            out = new FileOutputStream(dest);
            byte[] buf = new byte[READ_BUFFER_SIZE];
            int bytesRead;
            while ((bytesRead = in.read(buf)) > 0) {
                out.write(buf, 0, bytesRead);
            }
            Log.d(TAG,"copyFile  finished");
        } catch (Exception e) {
            Log.d(TAG,"copyFile  Exception:"+e);
        } finally {
            if(in != null) {
                in.close();
            }
            if(out != null) {
                out.close();
            }
        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值