Intellipaat 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
asked Nov 24, 2019 in Java by Anvi (10.2k points)
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...