Example usage for java.io File getName

List of usage examples for java.io File getName

Introduction

In this page you can find the example usage for java.io File getName.

Prototype

public String getName() 

Source Link

Document

Returns the name of the file or directory denoted by this abstract pathname.

Usage

From source file:AudioFilter.java

public static String getExtension(File f) {

    String ext = null;//from  w w  w . j  a  v a2 s  .c  o m
    String s = f.getName();
    int i = s.lastIndexOf('.');
    if (i > 0 && i < s.length() - 1) {
        ext = s.substring(i + 1).toLowerCase();
    }
    return ext;

}

From source file:Main.java

public static String getFileExtension(File f) {
    if (f != null) {
        String filename = f.getName();
        int i = filename.lastIndexOf('.');
        if (i > 0 && i < filename.length() - 1) {
            return filename.substring(i + 1).toLowerCase();
        }/*  ww w.jav  a2  s  .com*/
    }
    return null;
}

From source file:Main.java

public static void deleteFilesStartingWith(String string) {
    File specificFile = new File(string);
    File pFile = specificFile.getParentFile();
    if (pFile != null) {
        for (File f : pFile.listFiles()) {
            if (f.getName().startsWith(specificFile.getName())) {
                f.delete();/*www.  ja  v a 2  s.c o  m*/
            }
        }
    }
}

From source file:Main.java

public static boolean isWMAFile(File f) {
    return isWMAFile(f.getName());
}

From source file:Main.java

/**
 * Dialog for choosing file./*from  w w w  .  j  av a2 s .com*/
 * 
 * @param parent the parent component of the dialog, can be null
 * @return selected file or null if no file is selected
 */
public static File chooseImageFile(Component parent) {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileFilter(new FileFilter() {
        @Override
        public String getDescription() {
            return "Supported image files(JPEG, PNG, BMP)";
        }

        @Override
        public boolean accept(File f) {
            String name = f.getName();
            boolean accepted = f.isDirectory() || name.endsWith(".jpg") || name.endsWith(".jpeg")
                    || name.endsWith(".jp2") || name.endsWith(".png") || name.endsWith(".bmp");
            return accepted;
        }
    });

    fileChooser.showOpenDialog(parent);
    return fileChooser.getSelectedFile();
}

From source file:Main.java

public static boolean isMP3File(File in) {
    return isMP3File(in.getName());
}

From source file:Main.java

public static void deleteFiles(String path, String excludeSuffix) {
    File dir = new File(path);
    File[] files = dir.listFiles();
    if (files != null && files.length > 0) {
        for (File file : files) {
            if (excludeSuffix != null && file.getName().contains(excludeSuffix)) {
                continue;
            }/*from   w  w w . j a  va  2s.c  o  m*/
            file.delete();
        }
    }
}

From source file:Main.java

/**
 * Dialog for choosing file./*  ww  w . j a  v a  2 s .  c  o m*/
 * 
 * @param parent the parent component of the dialog, can be null
 * @return selected file or null if no file is selected
 */
public static File chooseImageFile(Component parent) {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileFilter(new FileFilter() {
        @Override
        public String getDescription() {
            return "Supported image files(JPEG, PNG, BMP)";
        }

        @Override
        public boolean accept(File f) {
            String name = f.getName();
            boolean accepted = f.isDirectory() || name.endsWith(".jpg") || name.endsWith(".jpeg")
                    || name.endsWith(".png") || name.endsWith(".bmp");
            return accepted;
        }
    });

    fileChooser.showOpenDialog(parent);
    return fileChooser.getSelectedFile();
}

From source file:Main.java

/**
 * Look for the resource directory with raw beneath it.
 *//*  w w w . j av a2  s.  c  o m*/
private static File findResRawDir(File dir) {
    for (File file : dir.listFiles()) {
        if (file.getName().equals(RESOURCE_DIR_NAME) && file.isDirectory()) {
            File[] rawFiles = file.listFiles(new FileFilter() {
                public boolean accept(File file) {
                    return file.getName().equals(RAW_DIR_NAME) && file.isDirectory();
                }
            });
            if (rawFiles.length == 1) {
                return rawFiles[0];
            }
        }
    }
    return null;
}

From source file:Main.java

private static String getProgramName() {
    String p = System.getProperty("program");
    if (p != null)
        return p;

    String cp = System.getProperty("java.class.path");
    if (cp.indexOf(File.pathSeparator) == -1) {
        File f = new File(cp);
        if (f.getName().equals("jtreg.jar"))
            return "java -jar jtreg.jar ";
    }/*from  www . ja v  a  2  s  . c o  m*/

    return "java " + Main.class.getName();
}