user6762070 user6762070 - 2 months ago 14
Java Question

case-sensitive processing of file names

Looking to verify that there's no case-sensitive methods for processing file/path references.

This is for a use like looking up a file with a ".pdf" and/or ".PDF" extension in the directory without knowing whether it is upper- or lower-case.

java.nio.file.Files
doesn't seem to have it. the only way I can think of is checking both cases or using
String.equalsIgnoreCase()
at it.

is there a better way of doing this?

Answer

you can use external jar like apache-commons , and read file without caring of extension type or case sensitivity

import org.apache.commons.io.FilenameUtils;
String fileNameWithOutExt = FilenameUtils.removeExtension(fileNameWithExt);

There also other ways will help you there :How to get the filename without the extension in Java?