Returns the base name (the substring before the last dot) of the given file. - Android java.io

Android examples for java.io:File Name

Description

Returns the base name (the substring before the last dot) of the given file.

Demo Code

public class Main {


  /**//from   ww w .j a va  2  s.  c  o  m
   * Returns the base name (the substring before the last dot) of the given file.
   * The dot is not included in the returned basename.
   *
   * @param name
   *          The filename in question.
   * @return The base name, or an empty string if no basename is found.
   */
  public static String getBaseName(String name) {
    int index = name.lastIndexOf('.');
    return index == -1 ? name : name.substring(0, index);
  }

}

Related Tutorials