// 临时文件名
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关于读取临时文件
最新推荐文章于 2021-06-03 02:52:03 发布