java.io.File and properties

Brian Jones cbj@gnu.org
Fri May 9 11:44:00 GMT 2003


Michael Koch <konqueror@gmx.de> writes:

> Am Freitag, 9. Mai 2003 07:00 schrieb Ranjit Mathew:
> > > Michael> I have question: java.io.File initializes a static
> > > variable called Michael> tmpdir at class initialization with the
> > > value of the property Michael> "java.io.tmpdir". If an app
> > > changes the value of this property after Michael>
> > > java.io.File.tmpdir has been initialized java.io.File will use
> > > the Michael> old value.
> > >
> > > What does the JDK do?
> >
> > Given the following program:
> > -------------------------------- 8<
> > -------------------------------- import java.util.*;
> > import java.io.*;
> >
> > public class T {
> >   public static void main( String[] args) throws Exception {
> >       System.out.println( System.getProperty( "java.io.tmpdir"));
> >       System.out.println( File.createTempFile( "java", null));
> >
> >       Properties props = System.getProperties( );
> >       props.put( "java.io.tmpdir", "C:\\TEMP\\");
> >
> >       System.out.println( System.getProperty( "java.io.tmpdir"));
> >       System.out.println( File.createTempFile( "mocha", null));
> >   }
> > }
> > -------------------------------- 8<
> > --------------------------------
> >
> > JRE 1.4.1_01 on Windows gives the following output:
> > -------------------------------- 8<
> > -------------------------------- D:\TEMP\
> > D:\TEMP\java35585.tmp
> > C:\TEMP\
> > D:\TEMP\mocha35586.tmp
> > -------------------------------- 8<
> > --------------------------------
> >
> > So while the change to "java.io.tmpdir" is noted, temporary files
> > are *still* created in the original temporary folder.
> >
> > So is this is a bug in Classpath?
> 
> On Linux JRE 1.4.1_01 behaves the same as on Windows. (*wonder* ;-))
> 
> The question is: Should we emulate this behaviour or do it the 
> classpath way ?
> 
> If we wanna do it the JRE way I will speak with Brian Jones about to 
> change classpath's behaviour.

The above from Sun looks stupid.  At what point is it useful to allow
programmer's to modify tmpdir at runtime but not let that change the
way createTempFile works?  I guess we can be bug compatible here, but
we may need a gnu.java.io.File.getTempDir() that works better.

Brian
-- 
Brian Jones <cbj@gnu.org>



More information about the Java mailing list