有人能告诉我如何在没有扩展名的情况下获取文件名吗?
fileNameWithExt = "test.xml";
fileNameWithOutExt = "test";
有人能告诉我如何在没有扩展名的情况下获取文件名吗?
fileNameWithExt = "test.xml";
fileNameWithOutExt = "test";
如果您和我一样,宁愿使用一些库代码,因为它们可能已经考虑到了所有特殊情况,例如,如果您传入null或路径中的点而不是文件名中的点,会发生什么情况,您可以使用以下代码:
import org.apache.commons.io.FilenameUtils;
String fileNameWithOutExt = FilenameUtils.removeExtension(fileNameWithExt);