// 临时文件名
final String tmpFileName = "comictmpsound.wav"; //Integer.toString(num++) + "." + type.substring(type.length() - 3, type.length());
app.deleteFile(tmpFileName);

FileOutputStream fos = null;

try {
fos = app.openFileOutput(tmpFileName, Context.MODE_PRIVATE);

byte[] b = new byte[32768];
int offset = 0;
int read = 0;
do {
read = ins.read(b);
if (read > 0) {
fos.write(b, 0, read);
offset += read;
}
} while (read > 0);
fos.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

// 打开临时文件
FileInputStream fis = null;
try {
fis = app.openFileInput(tmpFileName);
mp = new MediaPlayer();
mp.setDataSource(fis.getFD());
mp.prepare();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

更多相关文章

  1. 解决 Android 下载中文文件名问题
  2. 成功解决 Android 下载中文文件名
  3. 重命名sd卡中的文件名
  4. android读取SD卡下面所有的TXT文件名,listView显示出来。
  5. Gradle 修改生成apk时的文件名
  6. android 文件名长度限制
  7. android 根据res文件夹下(如res/raw)文件名获取其id
  8. Android Studio动态自定义编译输出的apk文件名

随机推荐

  1. android的动画
  2. Visual Studio 跨平台開發實戰(4) - Xama
  3. Android入门教程(四)之-------->Android
  4. Android NDK 简介
  5. android入门教程(十六)之-- 使用Intent传
  6. webView中js调用android方法一调用程序就
  7. 在定制android设备时,刷机后不全屏显示或
  8. Visual Studio 跨平台開發實戰(5) - Xama
  9. Android开发笔记(八十三)多语言支持
  10. 服务器端和客户端的上传代码