将原始文件复制到 SDCard 中? [英] Copying raw file into SDCard?

查看:31
本文介绍了将原始文件复制到 SDCard 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 res/raw 文件夹中有一些音频文件.由于某些原因,我想将此文件复制到我的 SDCard 时,我的应用程序启动.

I've some audio files in my res/raw folder. For some reasons, i want to copy this files to my SDCard When, my application starts.

我怎么能做到这一点?有人指导我吗?

How can i done this? Anyone guide me?

推荐答案

从资源中读取,写入 SD 卡上的文件:

Read from the resource, write to a file on the SD card:

InputStream in = getResources().openRawResource(R.raw.myresource);
FileOutputStream out = new FileOutputStream(somePathOnSdCard);
byte[] buff = new byte[1024];
int read = 0;

try {
   while ((read = in.read(buff)) > 0) {
      out.write(buff, 0, read);
   }
} finally {
     in.close();
     out.close();
}

这篇关于将原始文件复制到 SDCard 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆