Java File Name Get getFileName(String path)

Here you can find the source of getFileName(String path)

Description

get File Name

License

Open Source License

Declaration

public static String getFileName(String path) 

Method Source Code

//package com.java2s;
/**//  w ww .  j av a 2 s  . co m
 * Copyright 2012 Red Hat, Inc. and/or its affiliates.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA
 */

import java.io.File;

public class Main {
    public static String getFileName(String path) {
        return getFileName(path, true);
    }

    public static String getFileName(String path, boolean witjSuffix) {
        String[] segments = path.split("\\" + File.separatorChar);
        String resourceName = segments[segments.length - 1];
        int dotIndex = resourceName.indexOf('.');
        if (witjSuffix) {
            return resourceName;
        }
        if (dotIndex > -1) {
            return resourceName.substring(0, dotIndex);
        } else {
            return resourceName;
        }
    }
}

Related

  1. getFilename(String path)
  2. getFileName(String path)
  3. getFilename(String path)
  4. getFileName(String path)
  5. getFileName(String path)
  6. getFileName(String path)
  7. getFilename(String path)
  8. getFileName(String s)
  9. getFileName(String s)