[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

A patch for File.getCanonicalPath

From: Wu, Gansha
Subject: A patch for File.getCanonicalPath
Date: Wed, 29 Aug 2001 10:45:26 +0800

Like some previous patches we posted, File.getCanonicalPath hasn't 
counted in windows style path name like "drive:\dir\dir\file".
A patch is like this:

public String
getCanonicalPath() throws IOException
  String abspath = getAbsolutePath();
-  StringBuffer canonpath = new StringBuffer(separator);
+ //You have to deal with the chaos of naming of windows style path
+ if( System.getProperty("").indexOf("Windows") >= 0 )
+      abspath = abspath.replace('/', separatorChar);
+ StringBuffer canonpath;
+ if( abspath.startsWith(separator) ) //no drive prefix
+      canonpath = new StringBuffer(separator);
+ else
+      canonpath = new StringBuffer();  
   StringTokenizer st = new StringTokenizer(abspath, separator);
  ... ...

Of course it depends on File.getAbsolutePath to correctly handle such 
class of path names first.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]