Path file = Paths.get("C:/Temp/my.test");
DirectNIOBuffer buffer = new DirectNIOBuffer(file.toFile());
Files.deleteIfExists(file);
// the Files.deleteIfExists throws the following exception
// java.nio.file.FileSystemException: C:\Temp\my.test: The process cannot access the file because it is being used by another process.
// at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:86)
// at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
// at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
// at sun.nio.fs.WindowsFileSystemProvider.implDelete(WindowsFileSystemProvider.java:268)
// at sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(AbstractFileSystemProvider.java:108)
// at java.nio.file.Files.deleteIfExists(Files.java:1110)
// at test.MyTest.run(MyTest.java:28)
// at test.MyTest.main(MyTest.java:41)