How do I remove the file extension from Java?

Asked 2 years ago, Updated 2 years ago, 40 views

What is the best way to remove the file extension in Java, as shown below?

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

java string

2022-09-21 19:41

1 Answers

I think it is best to use the removeExtension() method of FilenameUtils class. If that'sir

str.substring(0, str.lastIndexOf('.'))

There's a way like this way.


2022-09-21 19:41

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.