I am working on one project in which I use java.nio.*
for file operation. Basically my product is working on server now I am creating files on server using Java 7.
Files.createFile(path)//For creating file.
But when I want to delete it using
Files.delete(path)
it gives me message
The process cannot access the file because it is being used by another process.**
Delete file code ....
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;
}
}
});