Rename file onto another in java

后端 未结 5 1959
迷失自我
迷失自我 2021-01-15 03:26

I have a file I need to rename to that of an existing file. This is a copy, modify, replace original operation on an existing JAR file. I\'ve got the first two steps done, I

5条回答
  •  迷失自我
    2021-01-15 03:35

    You're going to need to create two java.io.File objects: one for the new file, one for the old file.

    Lets call these oldFile and newFile.

    oldFile.delete()
    newFile.renameTo(oldFile);
    

    Edit: mmyers beat me to it.

提交回复
热议问题