Colons used to be file separators for Mac OS. The new OS X uses the slash as a file separator (like other Unices), but I think it may still allow the colon as a file separator, for Classic and Carbon stuff, I'm not sure. So, yeah, it's a file separator. What are the legal characters in a filename in Java? I mean, Unix allows everything except slash. Java must be fairly strict. If they're trying to avoid all platform-specific file separators, that means no /, \, :, and > at least. I'm sure there are probably others, if we dig through enough obscure OSes.
I do not think that will even compile ... will it? I tried and got illegal escape character compilation errors FileNameTest.java [11:1] illegal escape character String fileName = "04\:15\:44.txt"; But ulitmately I think the answer is that java doesn't really care about the filename. It is the OS that the file is to be written on that will impose the limits. So, if you know what OS you will be running on be sure not to use the file separator. You could use System.getProperty to get the file separator value and then check to make sure is is not in your filename.
In Windows, a file cannot contain special characters / \ : * ? | " < > ... there might be a few others. In Unix, there are relatively fewer special characters that are not allowed in the file name, such as /. Different flavors of Unix probably have slightly different rules. For example, I remember working on an old variant of Unix called 'Xenix', and it was possible to create a file name with an embedded '?' character. I don't think you can do that on Solaris. Checking for file names that contain file seperator (as returned by the path.seperator and file.seperator properties) is not sufficient. The OS may impose rules other than allowing specific characters. For example, you might not be allowed to create a file name with a leading space on some platforms. Another example -- some versions of Windows do not allow very long file names in very deep directories. The total length of the full pathname for the file must be less than some OS defined maximum. On Windows 2000, I tried to create a directory where the directory name was only 30 characters but the full path name was over 256 characters. I got 'The system could not find the path specified'. So if the OS can't create a file with a particular name, neither can Java.