Java JFileChooser getExtension(File f)

Here you can find the source of getExtension(File f)

Description

Method to get the extension of the file, in lowercase.

License

Open Source License

Return

the extension string

Declaration

public static String getExtension(File f) 

Method Source Code

//package com.java2s;

import java.io.File;

import javax.swing.JFileChooser;

public class Main {
    /**/*ww w . j  a va 2s  .co m*/
     * <p>
     * Method to get the extension of the file, in lowercase.
     * </p>
     *
     * @return the extension string
     */
    public static String getExtension(File f) {
        String s = f.getName();
        int i = s.lastIndexOf('.');
        if (i > 0 && i < s.length() - 1)
            return s.substring(i + 1).toLowerCase();
        return "";
    }

    /**
     * <p>
     * Method to get the extension of the file filter, in lowercase
     * </p>
     *
     * @return the extension string
     */
    public static String getExtension(JFileChooser f) {
        String description = f.getFileFilter().getDescription();
        int extensionStart = description.lastIndexOf(".");
        String extension = description.substring(extensionStart + 1, description.length() - 1);
        return extension;
    }
}

Related

  1. exportFile(JFileChooser fileChooser, String contents)
  2. fileChooser()
  3. getChoiceFileFromUser()
  4. getDir(String title, String initDir, boolean allowFiles, Component parent)
  5. getDriveDisplayName(File path)
  6. getFile()
  7. getFile(Component parent, String title, boolean write)
  8. getFile(FileFilter filter)
  9. getFile(String initialPath, final String extension, String TitleText)