Java – delete file extension

See the English answer > How do I trim a file extension from a string in Java? thirteen

package.zip    image.jpeg   video.avi etc

If it exists, I want to delete the extension How do I write this in Java? thank you!

Solution

It's like

if (name.indexOf(".") > 0)
    name = name.substring(0,name.lastIndexOf("."));

Index checking can avoid converting hidden files such as ". Profile" to ", while lastindexof() will focus on files such as cut kitty. Jpg is such a name

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>