By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,469 Members | 1,259 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,469 IT Pros & Developers. It's quick & easy.

Generic file name validation code?

P: 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
Sep 2 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
harry wrote:
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 ?
Sep 3 '07 #2

P: n/a
harry <a@abc.comwrote:
>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.
>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 da***@dagon.net <http://www.dagon.net/>
Sep 3 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.