Frank,
If the File class does not normalize the string used to create the
File, then there is a bug. There seems to be a bug in one version of
Linux and that has been reported to Sun. The constructor for File is
as follows:
public File(String pathname) {
if (pathname == null) {
throw new NullPointerException();
}
this.path = fs.normalize(pathname);
this.prefixLength = fs.prefixLength(this.path);
}
Notice that an object fs is called to normalize the pathname. The
object fs is created as a static field in all File classes as follows:
static private FileSystem fs = FileSystem.getFileSystem();
The FileSystem class is an abstract class that has to be implemented,
of course, for the os on which it exists. So, the basis for the class
is a JNI method:
public static native FileSystem getFileSystem();
Sun did not go to all this trouble without expecting the actual
separators to be normalized to whatever system a file is created on,
so that no matter what your path happens to be in creating a File
object, file.getName() should return the name without a file
separator. Is this helpful?
On 6/9/05, Frank W. Zammetti <[EMAIL PROTECTED]> wrote:
> Sorry guys, meant for this to go to the list only...
>
>
>
>
> On Thu, June 9, 2005 4:35 pm, Martin Cooper said:
> > Nope. If the upload came from a Windows system and the server is running
> on *nix, then the system separator is *not* what you want. You'd be
> looking for '/' in a path that uses '\' as the separator.
>
> Good point.
>
> OK, so thinking simplistically..
>
> final char PATH_SEP = File.pathSeparatorChar;
> final char ANTI_PATH_SEP = File.pathSeparatorChar == '/' ? '\\' : '/';
> String test = "/sub/dev/test.txt";
> int lastSep;
> lastSep = test.lastIndexOf(PATH_SEP);
> if (lastSep == -1) {
> lastSep = test.lastIndexOf(ANTI_PATH_SEP);
> }
>
> Should do the trick, no?
>
> > Martin Cooper
>
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
"You can lead a horse to water but you cannot make it float on its back."
~Dakota Jack~
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]