Java File Extension Name Get fileExt(String name)

Here you can find the source of fileExt(String name)

Description

Return filename extension.

License

GNU General Public License

Declaration


public static String fileExt(String name) 

Method Source Code

//package com.java2s;
/*/*from w ww .ja va 2 s  .  com*/
 * Copyright (C) 2015  University of Oregon
 *
 * You may distribute under the terms of either the GNU General Public
 * License or the Apache License, as specified in the LICENSE file.
 *
 * For more information, see the LICENSE file.
 */

public class Main {
    /** Return filename extension. */
    //----------------------------------------------------------------
    public static String fileExt(String name) {
        String ext = null;
        String fname = pathName(name);
        int index = fname.indexOf(".");
        if (index > 0)
            ext = fname.substring(index, fname.length());
        return ext;
    }

    /** Return the last directory or filenname in a path. */
    //----------------------------------------------------------------
    public static String pathName(String path) {
        int i = path.lastIndexOf("/");
        int j = path.lastIndexOf("\\");
        int k = i > j ? i : j;
        if (k < 0)
            return path;
        return path.substring(k + 1, path.length());
    }
}

Related

  1. extractExtension(String name)
  2. extractExtension(String s)
  3. extractExtension(String strFilename)
  4. extractExtension(String url)
  5. extractExtensions(String fileName)
  6. fileExt(String url)
  7. fileExtension(CharSequence path)
  8. fileExtension(String filename)
  9. fileExtension(String path)