Java operation -- get the file extension and remove the file extension

Source: Internet
Author: User

I received an email yesterday and learned that I want to attend a product department meeting. I guess it may be because of the demo problem of this product. So I got busy until half past three yesterday, and I realized that I was being played again in the morning. MM sent the email to me by mistake. Miserable reminder! I am still too connected...

However, yesterday, I spent half a day on file operations, obtaining file extensions, removing file extensions, and so on. Now, let's learn from each other. If it is not well written, please make a brick.

/** Java file operation to get the file extension ** created on: 2011-8-2 * Author: blueeagle */public static string getextensionname (string filename) {If (filename! = NULL) & (filename. length ()> 0) {int dot = filename. lastindexof ('. '); If (DOT>-1) & (DOT <(filename. length ()-1) {return filename. substring (DOT + 1) ;}} return filename;}/** Java file operation to obtain the file name without the extension ** created on: 2011-8-2 * Author: blueeagle */public static string getfilenamenoex (string filename) {If (filename! = NULL) & (filename. length ()> 0) {int dot = filename. lastindexof ('. '); If (DOT>-1) & (DOT <(filename. length () {return filename. substring (0, dot) ;}} return filename ;}

Here we mainly use two functions: lastindexof (string) and substring (INT, INT ).

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.