You cannot do this in a system-independent way, and I don't think there are standard APIs for checking the path name.
The best suggestion I can come up with is to use a regular expression to match the path name. The exact details will depend on how loose or tight you want to limit the path. For example, on Linux, you can disable spaces in path names, because although they are valid, they also cause problems for poorly written shell scripts. Or you can insist on absolute (or relative) tracks.
But before you run the regex, it would be nice to canonize the path with File.getCanonicalFile() . This will do things like checking for symbolic links, getting rid of redundant ". And" .. "s, and turning drive letters into standard form ... that should simplify your regular expression.
Stephen C Dec 18 '12 at 1:11 2012-12-18 01:11
source share