Java File Name Create fileName(String name)

Here you can find the source of fileName(String name)

Description

Return filename sans extension.

License

GNU General Public License

Declaration


public static String fileName(String name) 

Method Source Code

//package com.java2s;
/*/*from  w  ww .  j av a 2 s  . c o  m*/
 * Copyright (C) 2015  University of Oregon
 *
 * You may distribute under the terms of either the GNU General Public
 * License or the Apache License, as specified in the LICENSE file.
 *
 * For more information, see the LICENSE file.
 */

public class Main {
    /** Return filename sans extension. */
    //----------------------------------------------------------------
    public static String fileName(String name) {
        String fname = pathName(name);
        int index = name.indexOf(".");
        if (index > 0)
            fname = fname.substring(0, index);
        return fname;
    }

    /** Return the last directory or filenname in a path. */
    //----------------------------------------------------------------
    public static String pathName(String path) {
        int i = path.lastIndexOf("/");
        int j = path.lastIndexOf("\\");
        int k = i > j ? i : j;
        if (k < 0)
            return path;
        return path.substring(k + 1, path.length());
    }
}

Related

  1. fileName(String file, String moduleName)
  2. filename(String filename)
  3. filename(String filename)
  4. fileName(String filename)
  5. filename(String name)
  6. filename(String name, String ext)
  7. fileName(String path)
  8. fileName(String path)
  9. fileName(String path)