我正在使用java.nio.*
进行文件操作。基本上我的产品正在使用Java 7使用Java 7删除文件
Files.createFile(path)//For creating file.
服务器现在我创建服务器上的文件但是,当我想用
Files.delete(path)
它给我留言删除它
The process cannot access the file because it is being used by another process.**
删除文件代码....
Files.walkFileTree(start, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file,
BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException e)
throws IOException {
if (e == null) {
Files.delete(dir);
return FileVisitResult.CONTINUE;
} else {
// directory iteration failed
throw e;
}
}
});
[Java 7:Path vs File]的可能重复(http://stackoverflow.com/questions/6903335/java-7-path-vs-file) – 2012-07-26 13:11:42
您可能在某处写入文件后将其保持为打开状态在你的代码中。请记住始终关闭文件/流/等。在你完成之后。 Java 7提供了一个称为'试用资源'的整洁机制,为您提供帮助:http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html 恐怕没有什么可以做的了说,除非你提供更多的信息。 – toniedzwiedz 2012-07-26 13:13:33