Generic file name validation code?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • harry

    #1

    Generic file name validation code?

    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


  • Robert Larsen

    #2
    Re: Generic file name validation code?

    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 ?

    Comment

    • Mark Rafn

      #3
      Re: Generic file name validation code?

      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 getCanonicalFil e()
      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/>

      Comment

      Working...