-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.2.0, 1.2.2, 1.3.0, 1.3.1, 1.4.2
-
generic, x86
-
generic, windows_98, windows_nt, windows_2000
instances of FileInputStream, FileOutputStream, or RandomAccessFile are open on
the file at the time the VM exits, then the file will not be deleted. This
occurs only on win32, which does not allow a file to be deleted until all
streams on it have been closed. -- mr@eng 9/3/1998
Name: skT45625 Date: 06/09/2000
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
In the code below, the line that is commented-out causes the temporary file to
not be deleted on JVM exit. If the line is uncommented, the file does get
deleted.
Possibly the garbage collection for a RandomAccessFile should close the file
just in case it was not closed. If Java had destructors, the destructor for
this class would make sure to close the RandomAccessFile.
----------
import java.io.*;
public class DeleteTest {
private static String FILE_PREFIX = "inet";
private File tempFile;
private RandomAccessFile raf;
public DeleteTest() {
try {
tempFile = File.createTempFile(FILE_PREFIX, null);
System.out.println("TEMPFILE = " +
tempFile.getAbsolutePath());
raf = new RandomAccessFile(tempFile, "rw");
tempFile.deleteOnExit();
DbByteArrayOutputStream bout = new
DbByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bout);
String testStr = new String("TEST STRING");
out.writeObject(testStr);
out.flush();
bout.writeTo(raf);
bout.close();
//raf.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String args[]) {
DeleteTest app = new DeleteTest();
}
public class DbByteArrayOutputStream extends ByteArrayOutputStream {
public DbByteArrayOutputStream() {
super();
}
public DbByteArrayOutputStream(int size) {
super(size);
}
public synchronized void writeTo(DataOutput dstr) throws
IOException {
byte[] data = super.buf;
int len = super.size();
dstr.write(data, 0, len);
}
}
}
(Review ID: 105968)
======================================================================
- duplicates
-
JDK-4894964 If ImageOutputStream.close() is not explicitly called, temp file is not deleted
-
- Closed
-
-
JDK-6357433 FileInputStream.open(String) should use FILE_SHARE_DELETE share flag (win)
-
- Open
-
- relates to
-
JDK-4969756 win32: different apps can not load native libs with the same name from MLET
-
- Closed
-
-
JDK-6474389 test/java/util/zip/ZipFile/ManyZipFiles.java should clean up after itself
-
- Closed
-
-
JDK-6475005 Various regression tests are not cleaning up on exit
-
- Closed
-
-
JDK-6541641 (fc) java/nio/channels/FileChannel/ExpandingMap.java should clean up after itself
-
- Closed
-
-
JDK-5086661 JDK 1.5's temporary native libraries may not be deleted on VM exit
-
- Closed
-
-
JDK-4404721 Logging unclosed file handles from objects that are garbage-collected
-
- Open
-