Android关于读取临时文件
// 临时文件名
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();
}
}
}
更多相关文章
- 解决 Android 下载中文文件名问题
- 成功解决 Android 下载中文文件名
- 重命名sd卡中的文件名
- android读取SD卡下面所有的TXT文件名,listView显示出来。
- Gradle 修改生成apk时的文件名
- android 文件名长度限制
- android 根据res文件夹下(如res/raw)文件名获取其id
- Android Studio动态自定义编译输出的apk文件名