I have 2 files. You need to rename the new file to the old one and delete the old file.

I tried to do this:

boolean successful = tempFile.renameTo(inputFile); 

Did not work out.

    2 answers 2

    Naturally not work! And Java has nothing to do with it. You are trying to set 2 files with the same name in the same folder, the operating system will not allow this.

    You need to copy the name of the old file, delete it and even then rename the new one.

      It turned out this way (you also need to add error checking):

       inputFile.delete(); boolean successful = tempFile.renameTo(inputFile);