In Java 7, the new method java.nio.file.Paths.get(String path)will call InvalidPathExceptionif the path contains invalid characters for a specific file system, but in Java 6 or earlier, unfortunately, there is no such function.
Since the valid characters and length of the file name depend on the platform (or even the file system), you may not have a better option than trying to create a file and see if it works. In Java 6, creating a FileOutputStream with an illegal path will raise a rather nonspecific FileNotFoundException.
source
share