我正在尝试为我的录音机创建一个文件,但是这个文件不断获得一个随机名称.因为这很难处理,所以我希望在使用更有意义的名称创建文件后重命名该文件.
我在这里做错了吗?
outfile = File.createTempFile(amount + "_alarmsave",".3gp",storageDir); System.out.println("Old file: "+outfile.getAbsolutePath()); File newFile = new File(outfile.getParent(),"alarmsave_" + amount + ".3gp"); System.out.println("new file: "+newFile.getAbsolutePath()); if(outfile.renameTo(newFile)){ System.out.println("Succes! Name changed to: " + outfile.getName()); }else{ System.out.println("Failed"); }
LogCat输出:
01-13 18:27:40.264: I/System.out(22913): Old file: /mnt/sdcard/Personal Alarm/13_alarmsave1623959934.3gp 01-13 18:27:40.264: I/System.out(22913): new file: /mnt/sdcard/Personal Alarm/alarmsave_13.3gp 01-13 18:27:40.284: I/System.out(22913): Succes! Name changed to: 13_alarmsave1623959934.3gp