How to get only file names without extensions for files in Java

Asked 2 years ago, Updated 2 years ago, 44 views

Is there a way to get the file name without an extension?

fileNameWithExt = "test.xml";
fileNameWithOutExt = "test";

Like this.

file java

2022-09-22 22:14

1 Answers

You can write a class called FilenameUtils in the Apache common library.

import org.apache.commons.io.FilenameUtils;
String fileNameWithOutExt = FilenameUtils.removeExtension(fileNameWithExt);

You can use it like this.


2022-09-22 22:14

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.