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

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

问题描述

修剪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 Commons IO

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

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

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