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:Main.java

public static final String getExtensionWithDot(final File file) {
    if (file == null) {
        return "";
    }//from w w  w . ja va2  s .  co  m
    final String name = file.getName();
    final int index = name.lastIndexOf(".");
    if (index == -1) {
        return "";
    }
    return name.substring(index);
}

From source file:hoot.services.utils.FileUtils.java

public static File getFileFromFolder(String targetFolder, String fileName, String ext) {
    File ret = null;//w  ww  .  ja  va  2 s.c o  m
    String[] extension = { ext };
    File dir = new File(targetFolder);
    if (dir.isDirectory()) {
        List<File> files = (List<File>) org.apache.commons.io.FileUtils.listFiles(dir, extension, false);
        for (File file : files) {
            if (file.getName().equals(fileName + "." + ext)) {
                ret = file;
                break;
            }
        }
    }

    return ret;
}

From source file:com.px100systems.data.utility.BackupFile.java

public static boolean isBackup(File file) {
    return file.isFile() && file.getName().endsWith(EXTENSION);
}

From source file:Main.java

private static InputStream toInputStream(File file) throws IOException {
    InputStream in = new FileInputStream(file);
    if (file.getName().endsWith(".gz")) {
        in = new GZIPInputStream(in);
    }// w  ww.  j av a  2 s. com
    return in;
}

From source file:com.compomics.pladipus.core.control.util.JarLookupService.java

/**
 * This method looks for the appropriate jar in the given folder (excludes the lib folder)
 * @param regex the regex to match the file
 * @param searchRoot the root directory to start te search
 * @return a file matching the regex// w  w w . j  a  va  2s  . co  m
 * @throws UnspecifiedPladipusException
 */
public static File lookupFile(String regex, File searchRoot) throws UnspecifiedPladipusException {
    if (!searchRoot.isDirectory()) {
        throw new IllegalArgumentException(searchRoot + " is no directory.");
    }
    final Pattern p = Pattern.compile(regex);
    Iterator iterateFiles = FileUtils.iterateFiles(searchRoot, new String[] { "jar" }, true);
    List<File> matchingFiles = new ArrayList<>();
    while (iterateFiles.hasNext()) {
        File file = (File) iterateFiles.next();
        if (p.matcher(file.getName()).matches() & !file.getParent().equalsIgnoreCase("lib")) {
            matchingFiles.add(file);
        }
    }
    if (matchingFiles.size() > 1) {
        throw new UnspecifiedPladipusException("There are multiple file candidates (" + matchingFiles.size()
                + "), please ensure only a single version is present and try again");
    } else if (matchingFiles.isEmpty()) {
        throw new UnspecifiedPladipusException("There are no matching files present");
    }
    return matchingFiles.get(0);
}

From source file:Main.java

/**
 * If filename is "abc.def", return "def".
 * @param fin File to get extension//from   w ww  .j ava  2  s  . c  om
 * @return String extension without '.'
 */
public static String getExtension(File fin) {
    //if a file named "abc.def" , then return "def" .
    String fname = fin.getName();
    //To find the last ''
    int where = 0;
    for (int i = fname.length() - 1; i >= 0; --i) {
        if (fname.charAt(i) == '.') {
            where = i;
            break;
        }
    }

    if (where == 0 || where >= fname.length()) {
        return "";
    } else {
        return fname.substring(where + 1);
    }
}

From source file:com.bluexml.side.framework.facetmap.multimap.FacetMapCacheManager.java

private static String getMapKey(File file) {
    return file.getName().replaceFirst("map_([^\\.]*)\\.xml", "$1");
}

From source file:com.github.lucene.store.CreateJavaTestIndex.java

private static void findFiles(final List<File> result, final File dir) {
    for (final File file : dir.listFiles()) {
        if (file.getName().endsWith(".java")) {
            result.add(file);//from   www .  ja  v  a  2  s.  c o  m
        } else if (file.isDirectory()) {
            findFiles(result, file);
        }
    }
}

From source file:com.github.ipaas.ideploy.plugin.core.ChineseFileNameFilter.java

public static void deleteChineseNameFile(String prePath, File rootFile) {
    if (CharUtil.isChinese(rootFile.getName())) {
        try {/*from   w w w.j a va2s.  c o m*/
            if (rootFile.isDirectory()) {
                ConsoleHandler.error("??:"
                        + StringUtils.removePrefix(rootFile.getAbsolutePath().replaceAll("\\\\", "/"), prePath)
                        + "  ?");
                FileUtils.deleteDirectory(rootFile);
            } else {
                ConsoleHandler.error("??:"
                        + StringUtils.removePrefix(rootFile.getAbsolutePath().replaceAll("\\\\", "/"), prePath)
                        + "  ?");
                FileUtils.forceDelete(rootFile);
            }
        } catch (IOException e) {
            ConsoleHandler.error(":" + e.getMessage());
        }
    }
    if (rootFile.isDirectory()) {
        File[] files = rootFile.listFiles();
        for (int i = 0; i < files.length; i++) {
            System.out.println(files[i].getAbsolutePath());
            deleteChineseNameFile(prePath, files[i]); // ?
        }
    }
}

From source file:Main.java

public static void valiFileCanRead(File file) throws IOException {
    if (!file.canRead()) {
        throw new IOException("For file '" + file.getName() + "' not read access!");
    }/*from  ww w  .ja v  a  2  s . c  o  m*/
}