harry <a@abc.comwrote:
Quote:
>I need to validate a file name but it has to work on Windows & Unix!
What's "it" in that sentence? The code or the filename? It's very easy to
make the code work in multiple OSs, of course. It's very hard to make a
perfect validator to ensure that a filename would be valid in, say, the
Japanese release of Windows 95 when running under Solaris with an 8859-1
default encoding.
Quote:
>Does anybody know of java code that does this?
java.io.File forces some amount of well-formedness, and getCanonicalFile()
will normalize it using OS-specific code. If you try to actually create or
read the file, you'll be certain that the path is valid.
You won't know if it would be valid on another OS, but you really can't
know that anyway - different paths, drive letter conventions, permissions,
conflicting files, etc, even on the same OS on another machine will break.
--
Mark Rafn
dagon@dagon.net <http://www.dagon.net/>