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:com.fluke.application.IEODReader.java

private static void processFile(File file) throws IOException {
    String name = file.getName().split("\\.")[0];
    name = nameMap.get(name) == null ? name : nameMap.get(name);
    if (name.startsWith("_") || list.contains(name.toUpperCase())) {
        List<String> lines = FileUtils.readLines(file);
        process(name, lines);//from  w  w  w  .j a va 2s  .c  om
    }
}

From source file:Main.java

static public ArrayList<String> getSavedGestureNames(Context context) {

    ArrayList<String> gestureNames = new ArrayList<>();

    File[] files = context.getFilesDir().listFiles(new FilenameFilter() {
        @Override//from  w  w w .  j  ava  2  s.  co m
        public boolean accept(File dir, String filename) {
            return filename.endsWith(GESTURE_NAME_SUFFIX);
        }
    });

    //return the files without the suffix
    for (File file : files) {
        gestureNames.add(file.getName().substring(0, file.getName().indexOf(GESTURE_NAME_SUFFIX)));
    }

    return gestureNames;
}

From source file:Main.java

public static void addPluginIfMatches(File folderOrJar, String bundleName, Collection<File> result) {
    String name = folderOrJar.getName();
    if (folderOrJar.isFile()) {
        if (name.equals(bundleName + ".jar") || name.startsWith(bundleName + "_") && name.endsWith(".jar"))
            result.add(folderOrJar);/*from  w ww  .  j  ava  2 s  .c o  m*/
    } else {
        if (name.equals(bundleName) || name.startsWith(bundleName + "_"))
            result.add(folderOrJar);
    }
}

From source file:FileUtil.java

static void showDir(int indent, File file) throws IOException {
    for (int i = 0; i < indent; i++)
        System.out.print('-');
    System.out.println(file.getName());
    if (file.isDirectory()) {
        File[] files = file.listFiles();
        for (int i = 0; i < files.length; i++)
            showDir(indent + 4, files[i]);
    }/*from   ww w .j a  v a2  s  .  co m*/
}

From source file:Main.java

static public InputStream createInputStream(File file) throws IOException {
    String filename = file.getName().toLowerCase();
    if (filename.endsWith(".gz")) {
        // a buffered output stream sped processing up by 4X! in prod
        GZIPInputStream gis = new GZIPInputStream(new FileInputStream(file), 1024 * 1024); // 1 MB buffer
        return new BufferedInputStream(gis, 1024 * 1024); // 1 MB buffer
        /**        } else if (filename.endsWith(".lzf")) {
         // a buffered output stream is not necessary
         return new LZFInputStream(new FileInputStream(file));
         *///  w  w  w  . j av a2 s.co  m
    } else {
        return null;
    }
}

From source file:Main.java

public static int getNumCores() {
    try {//from w w w .j  a  v a  2 s.c o  m
        File dir = new File("/sys/devices/system/cpu/");
        File[] files = dir.listFiles(new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                return Pattern.matches("cpu[0-9]", pathname.getName());
            }

        });
        return files.length;
    } catch (Exception e) {
        e.printStackTrace();
        return 1;
    }
}

From source file:com.quavo.util.FileUtilities.java

/**
 * Gets the class files inside a directory.
 *
 * @param directory The directory./*w  ww  .ja va 2  s  .co m*/
 * @return An array of classes.
 * @throws IOException If an I/O exception is thrown.
 * @throws ClassNotFoundException If the class is not found.
 */
public static Class<?>[] getAllClasses(String directory) throws IOException, ClassNotFoundException {
    String path = Constants.OUTPUT_DIRECTORY + "/" + directory.replace('.', '/') + "/";
    File dir = new File(path);
    List<Class<?>> classes = new ArrayList<>();
    List<File> files = (List<File>) FileUtils.listFiles(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
    for (File file : files) {
        if (file.getName().endsWith(".class")) {
            classes.add(Class
                    .forName(file.getParent().replace("\\", ".").replace(Constants.OUTPUT_DIRECTORY + ".", "")
                            + '.' + file.getName().substring(0, file.getName().length() - 6)));
        }
    }
    return classes.toArray(new Class[classes.size()]);
}

From source file:com.splunk.shuttl.archiver.util.UtilsFile.java

/**
 * @return true if the file extension is csv
 *//*  w  w w. j a  v a2s  .  c o  m*/
public static boolean isCsvFile(File file) {
    return file.getName().endsWith(".csv");
}

From source file:Main.java

public static File findParentDirContainerFile(File file, final String fileKey) {
    if (fileKey.equals(file.getName())) {
        return file;
    }//from   w  w  w  . j  a v  a 2 s .  com
    File[] guessFileKeys = file.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return fileKey.equals(name);
        }
    });
    if (guessFileKeys.length > 0) {
        return file;
    }
    if (file.getParentFile() != null) {
        return findParentDir(file.getParentFile(), fileKey);
    } else {
        return file.getParentFile();
    }
}

From source file:Main.java

public static List<String> getAllFileLists(String dir) {
    List<String> results = new ArrayList<String>();

    File[] files = new File(dir).listFiles();
    //If this pathname does not denote a directory, then listFiles() returns null.

    for (File file : files) {
        if (file.isFile()) {
            results.add(file.getName());
        }/*from   w  w  w.ja  v  a  2 s.  c  o  m*/
    }
    return results;
}