Submitted On 06-MAR-2006
valjok
Other functions like math abs, max and sign are also trivial. But the reason for them to include into system libs is His Majesty REUSE. However, I think it is too much to include those has- and get- extension functions into API since they can be implemented inline:
hasExtension = (getExtension() != null)
checkExtension(e) = (getExtension().compareTo(e) == 0)
Does URL api include them? IMO, it is not desirable to clog up the File class by such tiny dust. The getBase method returning the part of the name preceding the extension would be more meaningful. Here are both from my Utils:
static String getExtension(String s) {
int i = s.lastIndexOf('.');
return i != -1 ? s.substring(i+1) : null;
}
static String getBase(String s) {
int i = s.lastIndexOf('.');
return i != -1 ? s.substring(0, i) : null;
}
Surprisingly, no IndexBoundException fires; therefore, the JFileChooser demo seems not optimal since checking on string length before calling substring is redundant:
public static String getExtension(File f) {
String ext = null;
String s = f.getName();
int i = s.lastIndexOf('.');
if (i > 0 && i < s.length() - 1) {
ext = s.substring(i+1).toLowerCase();
}
return ext;
}
Submitted On 06-MAR-2006
mlk
Extentions are the wrong way to do this, getMimeType would be better.
Submitted On 07-MAR-2006
jwenting
Sine file extensions are platform dependent (not just the existence but the meaning and delimitation) they don't belong in the core API.
If user wants them he can always create his own system for reading and interpreting them on a per-platform basis.
Submitted On 07-MAR-2006
valjok
The goolge "define:File extension" falls the definition into two cathegories:
1) MS-DOS extension is a 3-byte field in the the FAT file/direrctory record;
2) The character string after the right-most period in a filename.
The 2nd one is universal and it the subject of this RFE, since workaround "Write my own functions - easy to do" does not imply anything more complex than parsing filename.
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|