Java File Name Get getFileName(File file)

Here you can find the source of getFileName(File file)

Description

get File Name

License

Open Source License

Declaration

public static String getFileName(File file) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.File;
import java.util.regex.Pattern;

public class Main {
    public static String getFileName(File file) {
        String filename;// ww  w . j  av  a  2 s. co m
        String[] parts = file.toString().split(Pattern.quote("\\"));
        filename = parts[parts.length - 1]; //filename including extension

        String[] segs = filename.split(Pattern.quote("."));
        filename = segs[segs.length - 2];

        return filename;
    }

    public static String getFileName(String filename) {
        String[] parts = filename.toString().split(Pattern.quote("\\"));
        filename = parts[parts.length - 1]; //filename including extension      
        String[] segs = filename.split(Pattern.quote("."));
        filename = segs[segs.length - 2];
        return filename;
    }
}

Related

  1. getFileName(File file)
  2. getFileName(File file)
  3. getFileName(File file)
  4. getFileName(File file)
  5. getFilename(File file)
  6. getFileName(File file)
  7. getFilename(File file)
  8. getFilename(File file)
  9. getFilename(File file)