Java File Extension Name Extract getFileExtension(File file)

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

Description

get File Extension

License

Open Source License

Declaration

public static String getFileExtension(File file) 

Method Source Code


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

import java.io.*;

public class Main {
    public static String getFileExtension(File file) {
        String name = file.getName();
        int idx = name.lastIndexOf('.');
        if (!file.isDirectory() && idx != -1) {
            return name.substring(idx + 1, name.length()).toLowerCase();
        }/*from w ww.j ava2s .co m*/
        return "";
    }

    public static String getName(String path) {
        int index = path.lastIndexOf(File.separatorChar);
        if (index < 0) {
            return path;
        }
        return path.substring(index + 1);
    }
}

Related

  1. getFileExtension(File f)
  2. getFileExtension(File file)
  3. getFileExtension(File file)
  4. getFileExtension(File file)
  5. getFileExtension(File file)
  6. getFileExtension(File file)
  7. getFileExtension(File file)
  8. getFileExtension(File file)
  9. getFileExtension(File file)