java.io.File and properties

Ranjit Mathew rmathew4lists@hotmail.com
Fri May 9 06:20:00 GMT 2003


> 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?

Ranjit.



More information about the Java mailing list