JDK-4117370 : java.io.File.getParent cannot handle mixed slashes
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1998-03-05
  • Updated: 1998-03-05
  • Resolved: 1998-03-05
Related Reports
Duplicate :  
Description

Name: rm29839			Date: 03/05/98


If you construct a java.io.File with a filename
which contains forward slashes, the filename parsing
routines getParent() and getName() don't do the 
right thing, even though everything else about the
interface works fine.

Consider the following fragment:
File f = new File("C:/temp/dir1/dir2/fname");
System.out.print("Your file ")
if( f.exists()) 
   System.out.println("exists");
else{
   System.out.println("doesn't exist.  Please create it.");
   System.exit(0);
}

System.out.println("The parent is ["+f.getParent()+"]");
System.out.println("The name is ["+f.getName()+"]");
// parent aways returns empty
// name always contains the whole string.

At least be consistent!
(Review ID: 25941)
======================================================================

Comments
WORK AROUND Name: rm29839 Date: 03/05/98 you must normalize files to have slashes put in the standard direction before passing anything to the io.File API. ======================================================================
11-06-2004