Java File Name Get getFileName(String s)

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

Description

Return file name with no path but with extension

License

Open Source License

Parameter

Parameter Description
ss a parameter

Declaration

public static String getFileName(String s) 

Method Source Code

//package com.java2s;
/**/*w  w  w.j  ava2 s .  c o m*/
 * Copyright 2011 The ARIES Consortium (http://www.ariesonline.org) and
 * www.integratedmodelling.org. 
    
   This file is part of Thinklab.
    
   Thinklab is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published
   by the Free Software Foundation, either version 3 of the License,
   or (at your option) any later version.
    
   Thinklab 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
   General Public License for more details.
    
   You should have received a copy of the GNU General Public License
   along with Thinklab.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.File;

public class Main {
    /**
     * Return file name with no path but with extension
     * @param ss
     * @return
     */
    public static String getFileName(String s) {

        String ret = s;

        int sl = ret.lastIndexOf(File.separator);
        if (sl < 0)
            sl = ret.lastIndexOf('/');
        if (sl > 0)
            ret = ret.substring(sl + 1);

        return ret;
    }
}

Related

  1. getFileName(String path)
  2. getFileName(String path)
  3. getFileName(String path)
  4. getFileName(String path)
  5. getFilename(String path)
  6. getFileName(String s)
  7. getFileName(String s)
  8. getFileName(String template, String className, String packageName)
  9. getFileName(String url, String basePath)