Anyway to get the chars that are not valid in filenames
Alan Bateman
Alan.Bateman at Sun.COM
Wed Jul 29 00:46:16 PDT 2009
Paulo Levi wrote:
> In a platform independent manner of course.
> I sometimes have to convert strings into filenames (and it is
> important to users to read them yes) and fall afoul of this
> MSDN Path..::.GetInvalidFileNameChars Method seems like it would work
> as a windows binding. Anyway in the jdk (1.6) to do this?
> (and it really should be in the Paths api too).
>
That checking is done by the FileSystem#getPath method so you attempt to
create a method a Path with invalid path characters or syntax then it
throws InvalidPathException. Note that this checking is done at the
level of the operating system's definition of paths. You may encounter
volumes (or FileStores in this API) that are more restrictive, in which
case you will create a Path but perhaps fail when you later go to access
the file.
-Alan.
More information about the nio-discuss
mailing list