Android File Extension Name Get removeExtension(String s)

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

Description

Removes the path and extension from the input

Parameter

Parameter Description
s the input path to be stripped

Return

the filename without the path and extension

Declaration

public static String removeExtension(String s) 

Method Source Code

//package com.java2s;

public class Main {
    /**//  w ww  .j  ava2s.  co m
     * Removes the path and extension from the input
     * @param s the input path to be stripped
     * @return the filename without the path and extension
     */
    public static String removeExtension(String s) {
        String separator = System.getProperty("file.separator");
        String filename;

        // Remove the path upto the filename.
        int lastSeparatorIndex = s.lastIndexOf(separator);
        if (lastSeparatorIndex == -1) {
            filename = s;
        } else {
            filename = s.substring(lastSeparatorIndex + 1);
        }

        // Remove the extension.
        int extensionIndex = filename.lastIndexOf(".");
        if (extensionIndex == -1) {
            return filename;
        }

        return filename.substring(0, extensionIndex);
    }
}

Related

  1. indexOfExtension(String filename)
  2. isValidFileExtension(String extension)
  3. parseFileExtension(String filename)
  4. parseFileExtension(String filename)
  5. removeExtension(String file)
  6. getExtension(final String fileName)
  7. getFileExtenSion(File file)
  8. getFileExtension(String fullFilename, Boolean withDot)
  9. getFileExtensionOnly(String filename)