How do I get the extension of a file in Java?

Asked 2 years ago, Updated 2 years ago, 43 views

If I have a file like /path/to/file/foo.txt, I want to get only .txt, how can I do it? Is there a related method?

file java io

2022-09-22 13:06

1 Answers

If you look at Apache Commons IO, you'll find a class called FilenameUtils. If you use the getExtension method, You can obtain extensions. String ext = FilenameUtils.getExtension("/path/to/file/foo.txt");


2022-09-22 13:06

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.