We have underneath method in Java which should delete the source file when its close method is called.
private void appendFile(Path destination, Path source) {
try (FileChannel sourceChannel = FileChannel.open(source, StandardOpenOption.READ, StandardOpenOption.DELETE_ON_CLOSE);
FileChannel destinationChannel = FileChannel.open(destination, StandardOpenOption.WRITE, StandardOpenOption.APPEND)) {
destinationChannel.transferFrom(sourceChannel, destinationChannel.size(), sourceChannel.size());
} catch (IOException ex) {
// Do something with this exception
}
}
Now we run a functional integration test on this and see that the source file is not deleted.
Can someone help us with this ?
From
StandardOpenOption.DELETE_ON_CLOSEoption documentation:So it's only the best effort, not 100% guarantee that it will be deleted. Maybe it's still open by some other writer?