URL Class Loader & file deletion  
Author Message
S閎astien FOUCAULT





PostPosted: 2005-2-7 1:50:00 Top

java-programmer, URL Class Loader & file deletion Hello,

The following code always displays "File cannot be deleted".
Any idea on the way to allow a file to be deleted when it has been used
by a URL class loader to load code ?


public class ClassLoaderTester {
public static void main( String[] args ) {
try {
String s = "c:\\zob.jar";
URLClassLoader oCL = new URLClassLoader(
new URL[] {
new File(s).toURL()
} );
Class c = oCL.loadClass("com.mysql.jdbc.Driver");
Object o = c.newInstance();
o = null;
c = null;
oCL = null;

System.gc();
System.runFinalization();

File oFile = new File(s);
if ( !oFile.delete() ) {
System.err.println("File cannot be deleted");
}

}
catch ( Exception e ) {
e.printStackTrace();
}

}
}


Thank's in advance.
 
Roland





PostPosted: 2005-2-7 2:06:00 Top

java-programmer >> URL Class Loader & file deletion On 6-2-2005 18:50, S閎astien FOUCAULT wrote:

> Hello,
>
> The following code always displays "File cannot be deleted".
> Any idea on the way to allow a file to be deleted when it has been used
> by a URL class loader to load code ?
>
>
> public class ClassLoaderTester {
> public static void main( String[] args ) {
> try {
> String s = "c:\\zob.jar";
> URLClassLoader oCL = new URLClassLoader(
> new URL[] {
> new File(s).toURL()
> } );
> Class c = oCL.loadClass("com.mysql.jdbc.Driver");
> Object o = c.newInstance();
> o = null;
> c = null;
> oCL = null;
>
> System.gc();
> System.runFinalization();
>
> File oFile = new File(s);
> if ( !oFile.delete() ) {
> System.err.println("File cannot be deleted");
> }
>
> }
> catch ( Exception e ) {
> e.printStackTrace();
> }
>
> }
> }
>
>
> Thank's in advance.
Bug 4755278, which will not be fixed :-[
<http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4755278>
--
Regards,

Roland de Ruiter
___ ___
/__/ w_/ /__/
/ \ /_/ / \