views:

254

answers:

3

Does Java impose any extra restrictions of its own. Windows (upto Vista) does not allow names to include \ / < > ? * :

I know HOW to validate names (a regular expression).

I need to validate filenames entered by users.

My application does not need to run on any other platform, though, of course, I would prefer to be platform independent!

+1  A: 

No, you can escape any character that Java doesn't allow in String literals but the filesystem allows.

Also, if trying to port an Windows app to Mac or Unix it is best to use:

File.separator

To determine the correct file separator to use on each platform.

jjnguy
A: 

When you create a new File the inputted arguments will be normalized by a platform specific implementation of the java.io.FileSystem class. There are no Java specific restrictions that I know of.

and yes, always use File.separator.

Andrew
A: 

Java supports any string that can be expressed in Unicode (subject to some ridiculously long maximum length, Integer.MAX_VALUE), and file names are just another kind of string.

Of course, this means that you can try and refer to a file using a name that isn't supported by the underlying Operating System. If you do this, you'll get some kind of IOException when you try and use the File reference...

Bill Michell
The String length max is that of Integer.MAX_VALUE as the legth is stored in an int.
jjnguy