Java File Extension Name Get extractExtension(String s)

Here you can find the source of extractExtension(String s)

Description

does not include the dot.

License

Open Source License

Declaration

public static String extractExtension(String s) 

Method Source Code

//package com.java2s;
/*/*w w  w. java  2s.  c  o m*/
 * Copyright (C) 2009, Edmundo Albuquerque de Souza e Silva.
 *
 * This file may be distributed under the terms of the Q Public License
 * as defined by Trolltech AS of Norway and appearing in the file
 * LICENSE.QPL included in the packaging of this file.
 *
 * THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */

public class Main {
    /**
     * does not include the dot.
     * s can be filename + ext or full path.
     * 
     */
    public static String extractExtension(String s) {
        int index = s.lastIndexOf(".");
        if (index < 0)
            return "";
        return s.substring(index + 1, s.length());
    }
}

Related

  1. extractExtension(final String fileName)
  2. extractExtension(String fileName)
  3. extractExtension(String name)
  4. extractExtension(String strFilename)
  5. extractExtension(String url)
  6. extractExtensions(String fileName)
  7. fileExt(String name)