Answers for "java get file extension from filename"

3

java how to read file extension

private static String getFileExtension(File file) {
        String extension = "";
 
        try {
            if (file != null && file.exists()) {
                String name = file.getName();
                extension = name.substring(name.lastIndexOf("."));
            }
        } catch (Exception e) {
            extension = "";
        }
 
        return extension;
 
    }
Posted by: Guest on March-15-2020
0

how to get filename without extension in java

FilenameUtils.removeExtension(fileNameWithExt);
Posted by: Guest on August-23-2020
0

java get filename without extension

String fname = file.getName();
int pos = fname.lastIndexOf(".");
if (pos > 0) {
    fname = fname.substring(0, pos);
}
Posted by: Guest on September-29-2020

Code answers related to "java get file extension from filename"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language