'Java renameTo is returning false after having run successfully for months?
I have this code here that has been working for months now but suddenly decided to start throwing the exception in the if statement. Any ideas? Any other information that you need? The oldCSV.csv and newCSV.csv both exist in the directory already.
String filePath = "\\example\example\oldCSV.csv"
File oldFile = new File(filePath) // oldFile = "\\example\example\oldCSV.csv"
String parent = oldFile.getParent() // parent = "\\example\example"
File newFile = new File(parent, "newCSV.csv") // newFile = "\\example\example"
if(!oldFile.renameTo(newFile)) {
throw new Exception("Rename operation: ${oldFile.getName()} to newCSV.csv failed")
}
Solution 1:[1]
It is likely the case that newCSV.csv already exists renameTo is returning false because the rename was unsuccessful.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jeff Scott Brown |
