我正在尝试在Java中使用renameTo方法,但它只返回false并且不移动文件.
我错过了一步吗?有没有办法找出它为什么不移动文件?该删除方法不做什么事情.
这是我的代码显示我如何使用它:
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);
}
Run Code Online (Sandbox Code Playgroud)
这是一些系统信息:
Java:1.6.0_21; Java HotSpot(TM)客户端VM 17.0-b17
系统:在x86上运行的Windows XP 5.1; CP1252; en_US(nb)
| 归档时间: |
|
| 查看次数: |
4116 次 |
| 最近记录: |