parseFileExt static method
Returns the file extension of fileName
.
Throws FormatException if fileName
does not end with a file extension.
fileExt("my_image.jpg") == ".jpg"
fileExt("/path/to/my_image.png") == ".png"
fileExt("my_doc.info.pdf") == ".pdf"
fileExt("my_undefined") => throws FormatException
fileExt("my_unfinished.") => throws FormatException
Implementation
static String parseFileExt(String fileName) {
try {
String fileExt = fileName.substring(fileName.lastIndexOf("."));
if (_isValidFileExt(fileExt)) {
return fileExt;
} else {
throw FormatException("$fileExt is not a valid file extension.");
}
} on RangeError {
throw const FormatException("File names must contain a \".\" character.");
}
}