I'm trying to use the renameTo method in Java but it just returns false and doesn't move the file.
Am I missing a step? Is there a way to find out why it's not moving the file? The delete method doesn't do anything either.
Here's my code showing how I'm using it:
private void archiveOutputFile(File outputFile) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddhhmmssS");
String timeStamp = formatter.format(new Date());
String subFolderName = "Archive" + timeStamp;
File subFolder = new File(outputFile.getParent(),subFolderName);
subFolder.mkdir();
File newFile = new File(subFolder,outputFile.getName());
//outputFile.deleteOnExit(); //Doesn't work, nor does .delete()
boolean success = outputFile.renameTo(newFile);
}
Here's some system info:
Java: 1.6.0_21; Java HotSpot(TM) Client VM 17.0-b17
System: Windows XP version 5.1 running on x86; Cp1252; en_US (nb)