如何从 Java 中的字符串修剪文件扩展名? [英] How do I trim a file extension from a String in Java?

查看:26
本文介绍了如何从 Java 中的字符串修剪文件扩展名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Java 中修剪后缀的最有效方法是什么,如下所示:

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

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

推荐答案

这是我们不应该自己做的那种代码.把图书馆用于平凡的东西,把你的大脑留给困难的东西.

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.

在这种情况下,我建议使用 FilenameUtils.removeExtension() 来自 Apache公共 IO

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

这篇关于如何从 Java 中的字符串修剪文件扩展名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆