Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (10.2k points)

Can anyone tell me how to get the filename without the extension? Example:

fileNameWithExt = "test.xml";

fileNameWithOutExt = "test";

1 Answer

0 votes
by (46k points)

If you, like me, would preferably use some library code where they have thought of all special cases, such as what appears if you pass in null or dots in the path but not in the filename, you can practice the following:

import org.apache.commons.io.FilenameUtils;

String fileNameWithOutExt = FilenameUtils.removeExtension(fileNameWithExt);

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 9, 2019 in Java by Nigam (4k points)

Browse Categories

...