How do I trim a file extension from a String in Java?

omg picture omg · Jun 2, 2009 · Viewed 207.2k times · Source

What's the most efficient way to trim the suffix in Java, like this:

title part1.txt
title part2.html
=>
title part1
title part2

Answer

skaffman picture skaffman · Jun 13, 2009

This is the sort of code that we shouldn't be doing ourselves. Use libraries for the mundane stuff, save your brain for the hard stuff.

In this case, I recommend using FilenameUtils.removeExtension() from Apache Commons IO