File.renameTo () returns true, but the file has not been renamed

I am trying to create a file for my VCR, but this file continues to receive a random name. Since this is difficult to work with, I want to rename the file after creating it with a more meaningful name.

However, although it renameToreturns true, the file has not been renamed.

Am I doing something wrong here?

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 Output:

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
+5
source share
1 answer

RenameTo renames the actual file; it does not modify the object File. If you called .exists(), you will find that a new file exists, but the old one does not.

, File , . , File.renameTo ; .

+13

All Articles