deleteOnExit « API « Java I/O Q&A

1. Is there equivalent to java's File.deleteOnExit() in .NET BCL?

Probably I could make an application domain and hook to DomainUnload event, but I'd like to do that on primary app domain.

2. File Shredding & deleteOnExit()

private void wipe(File file) { try { FileChannel rwChannel = new RandomAccessFile(file, "rw").getChannel(); int numBytes = (int)rwChannel.size(); ByteBuffer buffer =, 0, numBytes); buffer.clear(); byte[] randomBytes = new byte[numBytes]; new Random().nextBytes(randomBytes); buffer.put(randomBytes); rwChannel.write(buffer); rwChannel.close(); } catch(Exception e) { JOptionPane.showMessageDialog(new JFrame(), e.getMessage(), "", 2); } } This above method attempts to wipe a given file. The files I want wiped are created ...

3. File.deleteOnExit Bug?

4. Status of BUG: File.deleteOnExit() does not work on open files (win32) ?

No. You will have to add a Runtime shutdownHoook and code it yourself. But this sort of thing worries me - deleting entire directory structures at any time, and especially at JVM exit time. Do you really need to do this? and why? what is the significance of the file that is still there preventing deletion of the directory? and why ...