文件大小为空"/>
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 写入文件,但是文件大小为空
发布评论