Java File Extension Name Extract extractFileExtension(String filePath)

Here you can find the source of extractFileExtension(String filePath)

Description

extract File Extension

License

Apache License

Declaration

public static String extractFileExtension(String filePath) 

Method Source Code

//package com.java2s;
/*/*w  ww.  j a  va  2s.  c  o  m*/
 * Copyright 2016 Rajesh Putta
       
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
    
   http://www.apache.org/licenses/LICENSE-2.0
    
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
 */

public class Main {
    public static String extractFileExtension(String filePath) {
        int index = filePath.lastIndexOf(".");

        if (index == -1) {
            throw new IllegalArgumentException("no extension for file path..." + filePath);
        }

        return filePath.substring(index + 1);
    }
}

Related

  1. extractFileExtension(String filename)
  2. extractFileExtension(String fileName)
  3. extractFileExtension(String filename)
  4. extractFileExtension(String filename)
  5. extractFileExtension(String fileName)
  6. extractFileExtension(String path)
  7. extractFileExtensionFromPath(String path)
  8. getFileExtension(File f)
  9. getFileExtension(File file)