简体   繁体   English

将raw或assets文件夹中的音频文件保存到sdcard android

[英]save audio file in raw or assets folder to sdcard android

Hi guys i am having a audio file in assets folder and i need to save the same file onto sdcard . 大家好我在资源文件夹中有一个音频文件,我需要将相同的文件保存到SD卡。

How to acheive this. 如何实现这一目标。

Below is the code i am using to save file 下面是我用来保存文件的代码

String filename = "filename.txt";
File file = new File(Environment.getExternalStorageDirectory(), filename);
FileOutputStream fos;
byte[] data = new String("data to write to file").getBytes();
try {
    fos = new FileOutputStream(file);
    fos.write(data);
    fos.flush();
    fos.close();
} catch (FileNotFoundException e) {
    // handle exception
} catch (IOException e) {
    // handle exception
}

please help 请帮忙

try this 尝试这个

AssetManager mngr = getAssets();
InputStream path = mngr.open("music/music1.mp3"); 

                    BufferedInputStream bis = new BufferedInputStream(path,1024);

                    //get the bytes one by one
                    int current = 0;

                    while ((current = bis.read()) != -1) {

                        baf.append((byte) current);
                    }
}
byte[] bitmapdata  = baf.toByteArray();

After converting into byte array copy this into the sdcard as follows 转换成字节数组后,将其复制到sdcard中,如下所示

File file = new File(Environment.getExternalStorageDirectory(), music1.mp3);
FileOutputStream fos;

try {
    fos = new FileOutputStream(file);
    fos.write(bitmapdata  );
    fos.flush();
    fos.close();
} catch (FileNotFoundException e) {
    // handle exception
} catch (IOException e) {
    // handle exception
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过将音频保存在sdcard上或使用应用程序的安装地址来访问原始或资产文件夹中的音频? - How to access an audio in raw or assets folder by save it on sdcard or using app's installation address? Android App /可以从Raw或Assets文件夹而不是/ SDCard /播放音频/视频文件 - Android App/ to paly audio/videos files from Raw or Assets folder instead of /SDCard/ 如何将原始文件夹中的音乐文件保存到android中的SD卡中 - How to save music files from raw folder into sdcard in android Android:以编程方式将文件从sdcard复制到应用程序的资产文件夹 - Android: Copy file from sdcard to app's assets folder programmatically android从资源文件夹共享音频文件 - android share audio file from assets folder 如何使用MediaRecorder录制音频文件并将其保存到android中的sdcard - How to record audio file using MediaRecorder and save to sdcard in android 将SD卡文件加载到Assets文件夹的html文件中 - Load sdcard file to html file of assets folder res / raw,assets或sdcard? - res/raw, assets or sdcard? Android SoundPool仅可以从Raw或资产文件夹播放音频/视频,而不能从SDcard播放音频/视频? - Android SoundPool only can play audio/Video from Raw or asset folder not from SDcard? 将(.txt)文件保存到Android中的资产文件夹? - Save a (.txt) file to the Assets Folder in Android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM