Connecting Tech Pros Worldwide Help | Site Map

Generic file name validation code?

  #1  
Old September 2nd, 2007, 12:25 PM
harry
Guest
 
Posts: n/a
I need to validate a file name but it has to work on Windows & Unix!

Does anybody know of java code that does this?

thanks in advance

harry


  #2  
Old September 3rd, 2007, 07:25 AM
Robert Larsen
Guest
 
Posts: n/a

re: Generic file name validation code?


harry wrote:
Quote:
I need to validate a file name but it has to work on Windows & Unix!
>
Does anybody know of java code that does this?
>
thanks in advance
>
harry
>
>
This sounds easy to write using the java.util.regex package.
How should a file name look like ?
  #3  
Old September 3rd, 2007, 08:05 PM
Mark Rafn
Guest
 
Posts: n/a

re: Generic file name validation code?


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/>
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
XML Validation using XSD in IE 6.0 anilthuruthy answers 8 January 27th, 2009 03:06 AM
How to Make a File Download Script with Perl KevinADC insights 1 December 4th, 2008 06:44 AM
handling validateRequest=true in code behind. is there a workarou R Reyes answers 13 November 16th, 2005 02:38 PM
XML validation error. Help required stuart dent via .NET 247 answers 1 November 12th, 2005 03:50 AM