Check for Correct File Name Syntax

What is the most efficient way to check if a String can be used as a file name? Here is my current (bulky) way:

public static boolean isValidFileName(String s) {

try {

File file = new File(s);

file.mkdir();

file.delete();

return true;

}

catch (Exception e) {

return false;

}

}

Thanks!

[363 byte] By [hodaddya] at [2007-11-26 18:20:08]
# 1

Sorry about the poor code format, above. This is my first posting experience here.

public static boolean isValidFileName(String s) {

try {

File file = new File(s);

file.mkdir();

file.delete();

return true;

}

catch (Exception e) {

return false;

}

}

hodaddya at 2007-7-9 5:53:54 > top of Java-index,Core,Core APIs...
# 2
1) What happens if the file already exists?2) You should really use file.mkdirs() instead of file.mkdir().3) What is going to cause the exception? mkdir(), mkdirs() and delete() do not throw an exception if they fail; they return false.
sabre150a at 2007-7-9 5:53:54 > top of Java-index,Core,Core APIs...
# 3
Thanks for the questions. They help me improve my current system for checking for acceptable syntax. But is there any way to check to see fi a file name is allowed by the platform without without making and then deleting a directory?
hodaddya at 2007-7-9 5:53:54 > top of Java-index,Core,Core APIs...