JDK-4071312 : java.io.File: Problem accessing files in root directory
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.1.3
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_95
  • CPU: x86
  • Submitted: 1997-08-12
  • Updated: 1998-01-22
  • Resolved: 1998-01-22
Related Reports
Duplicate :  
Description

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 - ###@###.###
======================================================================

Comments
WORK AROUND Name: rlT66838 Date: 08/12/97 "C:\." works instead of "C:\" ======================================================================
11-06-2004

EVALUATION The second and third cases duplicate the problem reported in 4065189 (java.io.File.list does not work when slash appended to drive). The first case is a duplicate of 4070044 (getCanonicalPath does not handle drive-relative paths). As the first bug has been fixed, I'm closing this as a duplicate of the second. -- mr@eng 1/21/1998
21-01-1998