Returns a copy of the given path with the extension omitted. - Android File Input Output

Android examples for File Input Output:File Path

Description

Returns a copy of the given path with the extension omitted.

Demo Code

// Copyright 2009-2011 Google, All Rights reserved
//package com.java2s;

public class Main {
    /**//from w  w  w  . j a  v a2  s  .  co m
     * Returns a copy of the given path with the extension omitted.
     *
     * @param path the path
     * @return path, with the extension elements omitted.
     */
    public static String trimOffExtension(String path) {
        int lastSlash = path.lastIndexOf('/');
        int lastDot = path.lastIndexOf('.');
        return (lastDot > lastSlash) ? path.substring(0, lastDot) : path;
    }
}

Related Tutorials