我通过OmRecorder录制后以编程方式重命名“temp-record.mp3”文件,录制后和重命名文件之前,MP3文件似乎播放正常并且有效。但在将“temp-record.mp3”文件重命名为动态“userId-record-systime.mp3”之后,它会被破坏并且不会播放。
我正在使用以下函数重命名:
public static boolean renameFile(String fromFilePathWithExt,String toFilePathWithExt){
LogUtils.d("from: "+fromFilePathWithExt);
LogUtils.d("to: "+toFilePathWithExt);
File dir = Environment.getExternalStorageDirectory();
if(dir.exists()){
File from = new File(fromFilePathWithExt);
File to = new File(toFilePathWithExt);
if(from.exists()) {
return from.renameTo(to);
}
}
return false;
}
我也通知了这个issues in Omrecorder回购,但我仍然感到困惑,我做错了什么?
尝试做:
new file(“loc / xyz1.mp3”)。renameTo(new File(“loc / xyz.mp3”));
这应该会自动覆盖原始文件。这个答案来自这里:enter link description here