Name: rlT66838 Date: 08/12/97
The following code illustrates unexpected
behavior when dealing with a drive's root
directory on Win 95. Creating a File using
C: or C:\ does not work properly. It is
understandable that C: would not work (although
its manner of not working is bizarre), but
C:\ should work. More details in the comments
within the code.
// Illustrates JRE 1.1.3's unfortunate behavior on Windows 95. Run from
// some directory other than c:\ for best results.
import java.io.*;
public class pain
{
public static void main( String args[] )
{
File f1, f2, f3;
String contents[];
// Three ways of specifying the C drive.
f1 = new File( "c:" );
f2 = new File( "c:\\" );
f3 = new File( "c:\\." );
// Note the interesting absolute path for f1.
System.out.println( "f1: " + f1.getAbsolutePath() );
System.out.println( "f2: " + f2.getAbsolutePath() );
System.out.println( "f3: " + f3.getAbsolutePath() );
// f1 gets the right number of files despite its weird absolute
// path.
try
{
contents = f1.list();
System.out.println( " Num in f1: " + contents.length );
}
catch ( NullPointerException e )
{
System.out.println( "f1.list() is null" );
}
// f2 thinks there are no files in c:
try
{
contents = f2.list();
System.out.println( " Num in f2: " + contents.length );
}
catch ( NullPointerException e )
{
System.out.println( "f2.list() is null" );
}
// This works.
try
{
contents = f3.list();
System.out.println( " Num in f3: " + contents.length );
}
catch ( NullPointerException e )
{
System.out.println( "f3.list() is null" );
}
}
}
company - Zeh Graphic Systems, Inc. , email - ###@###.###
======================================================================
- duplicates
-
JDK-4070044 java.io.File.getCanonicalPath does not handle drive-relative paths (win32)
-
- Closed
-