android FileOutputStream 写入文件,但是文件大小为空

编程入门 行业动态 更新时间:2024-10-26 08:21:12

android FileOutputStream 写入文件,但是<a href=https://www.elefans.com/category/jswz/34/1756941.html style=文件大小为空"/>

android FileOutputStream 写入文件,但是文件大小为空

最近做录音 pcm文件转 mp3,再分段重复录制功能时,刚停止又重新开始录制;发现写入的文件运行都正常,最终的.mp3文件没有;

排查发现:

Logger.i(TAG, "run() FileOutputStream之前; file.exists(): " + file.exists());
this.os = new FileOutputStream(file);
Logger.i(TAG, "run() FileOutputStream之后;file.exists(): " + file.exists());

之前 file是不存在的,但是执行之后存在了,但是,在最终写入文件时判断有不存在了,比较奇怪,最终解决方法如下:

Logger.e(TAG, "lameData() os.write 开始写;file.exists(): " + file.exists() + " file.length = " + file.length());
if (!file.exists()) {Logger.i(TAG, "run() FileOutputStream之前; file.exists(): " + file.exists());this.os = new FileOutputStream(file);Logger.i(TAG, "run() FileOutputStream之后;file.exists(): " + file.exists());
}
os.write(mp3Buffer, 0, encodedSize);
Logger.e(TAG, "lameData() os.write 写入后;file.exists(): " + file.exists() + " file.length = " + file.length());

在调用os.write(mp3Buffer, 0, encodedSize); 方法之前再判断一下文件是否存在,不存在,则重新this.os = new FileOutputStream(file);调用,调用后文件存在了;

更多推荐

android FileOutputStream 写入文件,但是文件大小为空

本文发布于:2023-12-06 04:00:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1666371.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件大小   为空   文件   android   FileOutputStream

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!