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.technofovea.packbsp.PackbspUtil.java

/**
 * Efficiently copies a given file, returning a temporary copy which will be
 * removed when execution finishes.//from w w w .jav  a 2 s .co m
 * 
 * @param source Source file to copy.
 * @return The copied file.
 * @throws IOException
 */
public static final File createTempCopy(File source) throws IOException {
    String ext = FilenameUtils.getExtension(source.getName());
    File dest = File.createTempFile("packbsp_temp_", "." + ext);
    dest.deleteOnExit();
    FileInputStream fis = new FileInputStream(source);
    FileOutputStream fos = new FileOutputStream(dest);
    IOUtils.copy(fis, fos);
    fis.close();
    fos.close();
    return dest;
}

From source file:com.fizzed.stork.assembly.AssemblyUtils.java

static public void copyStandardProjectResources(File projectDir, File outputDir) throws IOException {
    FileUtils.copyDirectory(projectDir, outputDir, new FileFilter() {
        @Override/*w  w w .  j  av  a 2 s .co m*/
        public boolean accept(File pathname) {
            String name = pathname.getName().toLowerCase();
            if (name.startsWith("readme") || name.startsWith("changelog") || name.startsWith("release")
                    || name.startsWith("license")) {
                return true;
            } else {
                return false;
            }
        }
    });
}

From source file:com.gs.obevo.util.FileUtilsCobra.java

public static Function<File, String> toFileName() {
    return new Function<File, String>() {
        @Override//from www  .ja  v a  2 s . co m
        public String valueOf(File object) {
            return object.getName();
        }
    };
}

From source file:com.michelin.cio.hudson.plugins.maskpasswords.MaskPasswordsURLEncodingTest.java

private static void grep(File dir, String text, String prefix, Set<String> matches) throws IOException {
    File[] kids = dir.listFiles();
    if (kids == null) {
        return;/*from   www .j  av a 2  s . co m*/
    }
    for (File kid : kids) {
        String qualifiedName = prefix + kid.getName();
        if (kid.isDirectory()) {
            grep(kid, text, qualifiedName + "/", matches);
        } else if (kid.isFile() && FileUtils.readFileToString(kid).contains(text)) {
            matches.add(qualifiedName);
        }
    }
}

From source file:de.tudarmstadt.ukp.dkpro.core.api.lexmorph.tagset.MappingsTest.java

public static void assertTagsetMapping(Collection<File> files) throws IOException {
    for (File file : files) {
        boolean failure = false;
        System.out.printf("== %s ==%n", file.getName());
        MappingProvider mappingProvider = new MappingProvider();
        mappingProvider.setDefault(MappingProvider.LOCATION, file.toURI().toURL().toString());
        mappingProvider.configure();//w w w  .  j  av a 2 s  .  com
        for (String tag : mappingProvider.getTags()) {
            String typeName = mappingProvider.getTagTypeName(tag);
            try {
                Class.forName(typeName);
            } catch (Throwable e) {
                System.out.printf("%s FAILED: %s %n", tag, e.getMessage());
                failure = true;
            }
        }
        assertFalse(failure);
    }
}

From source file:Main.java

/**
 * Show a dialog that asks the user if a certain file should be overwritten. Nothing
 * will happen if the given file does not exist.
 * @param parent/*from www. ja v  a2  s .co m*/
 * @param file File to be overwritten.
 * @return {@code true} if the user confirms or if the file does not exist.
 */
public static boolean confirmFileWriting(Component parent, File file) {
    if (!file.exists())
        return true;

    return JOptionPane.showConfirmDialog(parent,
            "The file '" + file.getName() + "' does already exist. Overwrite?", "Confirm",
            JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
}

From source file:Main.java

public static Document parseDocument(final File xmlFile)
        throws ParserConfigurationException, SAXException, IOException {
    log.finer("Parsing document from file " + xmlFile.getName());
    DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    domFactory.setNamespaceAware(true);//from   w w w  .  j  ava 2  s . c o m
    DocumentBuilder builder = domFactory.newDocumentBuilder();
    return builder.parse(xmlFile);

}

From source file:com.googlecode.jtiger.modules.ecside.resource.MimeUtils.java

/**
 * Return the mime type for a file. The extension is parsed out and the
 * method to get mime type by extension is called. Extension mappings are
 * found in the mimeTypes.properties file in the org.extremecomponents.util
 * package.//from   w ww .  ja va2  s . c o  m
 */
public static String getFileMimeType(File file) {
    if (file == null) {
        return null;
    }

    return getFileMimeType(file.getName());
}

From source file:net.pocketpixels.hubmanager.DBmanager.java

/**
 *Loads all the objects of class type out of JSON from the given folder
 * @param type The class of the objects to be loaded
 * @param loc the location of the folder to load the data from
 * @return returns a HashMap of the file names and the Objects loaded
 *//*from  www.  ja v a  2s. c om*/
public static HashMap<String, Object> loadAllObj(Class type, File loc) {
    if (!loc.exists()) {
        loc.mkdirs();
        return null;
    }
    HashMap<String, Object> rtn = new HashMap<String, Object>();
    for (File f : loc.listFiles()) {
        rtn.put(f.getName(), loadObj(type, f));
    }
    return rtn;
}

From source file:com.github.megatronking.svg.cli.Main.java

private static void svg2vectorForFile(File inputFile, File outputFile, int width, int height) {
    if (inputFile.getName().endsWith(".svgz")) {
        File tempUnzipFile = new File(inputFile.getParent(), FileUtils.noExtensionLastName(inputFile) + ".svg");
        try {/*w  ww  .  j  a v  a 2  s .  com*/
            FileUtils.unZipGzipFile(inputFile, tempUnzipFile);
            svg2vectorForFile(tempUnzipFile, outputFile, width, height);
        } catch (IOException e) {
            throw new RuntimeException("Unzip file occur an error: " + e.getMessage());
        } finally {
            tempUnzipFile.delete();
        }
    } else if (inputFile.getName().endsWith(".svg")) {
        Svg2Vector.parseSvgToXml(inputFile, outputFile, width, height);
    }
}