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 void zipChildren(File folder, String prefix, ZipOutputStream out) throws IOException {
    File[] files = folder.listFiles();
    if (files == null)
        return;/*www . jav a2s.  com*/
    for (File file : files) {
        if (file.isFile()) {
            String name = prefix + file.getName();
            ZipEntry entry = new ZipEntry(name);
            entry.setTime(file.lastModified());
            out.putNextEntry(entry);
            loadFromFile(file, out);
            out.closeEntry();
        } else if (file.isDirectory()) {
            zipChildren(file, prefix + file.getName() + "/", out);
        }
    }

}

From source file:app.utils.ImageUtilities.java

public static Image readImageFromFile(File imgFile) throws IOException {
    String imgName = imgFile.getName();
    BufferedImage img = ImageIO.read(imgFile);
    Pixel[][] pixels = new Pixel[img.getWidth()][img.getHeight()];
    for (int x = 0; x < img.getWidth(); x++) {
        for (int y = 0; y < img.getHeight(); y++) {
            int redValue = new Color(img.getRGB(x, y)).getRed();
            int greenValue = new Color(img.getRGB(x, y)).getGreen();
            int blueValue = new Color(img.getRGB(x, y)).getBlue();
            pixels[x][y] = new Pixel(redValue, greenValue, blueValue);
        }/* w w  w .ja v a  2  s . c om*/
    }
    return new Image(imgName, pixels, img.getRaster().getNumDataElements());
}

From source file:io.github.bunnyblue.droidfix.classcomputer.gradleImpl.GradleImpl15.java

public static void extract() {
    File srcDir = new File(Configure.getInstance().getProguardJarFolder());
    Collection<File> jars = FileUtils.listFiles(srcDir, new String[] { "jar" }, true);
    List<File> jarsList = (List<File>) jars;
    File jar = jarsList.get(0);
    String extractClasses = jar.getParentFile().getAbsolutePath() + File.separator
            + jar.getName().substring(0, jar.getName().indexOf(".jar"));
    Configure.getInstance().setTransformedClassDir(extractClasses);
    File targetFile = new File(extractClasses);
    try {/*from   www . j a va2s. c o m*/
        FileUtils.deleteDirectory(targetFile);
    } catch (IOException e) {
        e.printStackTrace();
    }
    ZipUtil.unpack(jar, targetFile);
}

From source file:org.jtheque.i18n.I18NResourceFactory.java

/**
 * Construct a I18NResource from the given file.
 *
 * @param file The file to use to create the I18NResource.
 *
 * @return The I18NResource corresponding to the given file.
 *//*from  w  w w  .  j av  a 2  s .  c om*/
public static I18NResource fromFile(File file) {
    return new I18NResourceImpl(file.getName(), new FileSystemResource(file));
}

From source file:com.wipro.ats.bdre.tdimport.FileScan.java

public static void scanAndAddToQueue() {
    try {//w  w  w  .  j av  a2 s . c  o m
        String scanDir = TDImportRunnableMain.getMonitoredDirName();
        LOGGER.debug("Scanning directory: " + scanDir);
        File dir = new File(scanDir);
        if (!dir.exists()) {
            LOGGER.info("Created monitoring dir " + dir + " success=" + dir.mkdirs());
        }
        File arcDir = new File(scanDir + "/" + TDImportRunnableMain.ARCHIVE);
        if (!arcDir.exists()) {
            LOGGER.info("Created monitoring dir " + arcDir + " success=" + arcDir.mkdirs());
        }
        // Getting list of files recursively from directory except '_archive' directory
        Collection<File> listOfFiles = FileUtils.listFiles(dir,
                new RegexFileFilter(TDImportRunnableMain.getFilePattern()),
                new RegexFileFilter("^(?:(?!" + TDImportRunnableMain.ARCHIVE + ").)*$"));
        String fileName = "";
        FileCopyInfo fileCopyInfo = null;
        for (File file : listOfFiles) {
            fileName = file.getName();
            LOGGER.debug("Matched File Pattern by " + fileName);
            fileCopyInfo = new FileCopyInfo();
            fileCopyInfo.setFileName(fileName);
            fileCopyInfo.setSubProcessId(TDImportRunnableMain.getSubProcessId());
            LOGGER.debug("subprocessid in file scan =" + TDImportRunnableMain.getSubProcessId() + " "
                    + fileCopyInfo.getSubProcessId());
            fileCopyInfo.setSrcLocation(file.getAbsolutePath());
            fileCopyInfo.setTdTable(TDImportRunnableMain.getTdTable());
            fileCopyInfo.setFileSize(file.length());
            fileCopyInfo.setTimeStamp(file.lastModified());
            fileCopyInfo.setTdDB(TDImportRunnableMain.getTdDB());
            fileCopyInfo.setTdUserName(TDImportRunnableMain.getTdUserName());
            fileCopyInfo.setTdPassword(TDImportRunnableMain.getTdPassword());
            fileCopyInfo.setTdDelimiter(TDImportRunnableMain.getTdDelimiter());
            fileCopyInfo.setTdTpdid(TDImportRunnableMain.getTdTpdid());
            FileMonitor.addToQueue(fileName, fileCopyInfo);
        }
    } catch (Exception err) {
        LOGGER.error("Error in scan directory ", err);
        throw new BDREException(err);
    }
}

From source file:Main.java

static File makeTempJar(File moduleFile) throws IOException {
    String prefix = moduleFile.getName();
    if (prefix.endsWith(".jar") || prefix.endsWith(".JAR")) { // NOI18N
        prefix = prefix.substring(0, prefix.length() - 4);
    }/* ww  w.j  ava2s .  c o  m*/
    if (prefix.length() < 3)
        prefix += '.';
    if (prefix.length() < 3)
        prefix += '.';
    if (prefix.length() < 3)
        prefix += '.';
    String suffix = "-test.jar"; // NOI18N
    File physicalModuleFile = File.createTempFile(prefix, suffix);
    physicalModuleFile.deleteOnExit();
    InputStream is = new FileInputStream(moduleFile);
    try {
        OutputStream os = new FileOutputStream(physicalModuleFile);
        try {
            byte[] buf = new byte[4096];
            int i;
            while ((i = is.read(buf)) != -1) {
                os.write(buf, 0, i);
            }
        } finally {
            os.close();
        }
    } finally {
        is.close();
    }
    return physicalModuleFile;
}

From source file:docbook.ArticleRoundTripTest.java

private static TestSuite listCases(File dir) {
    TestSuite cases = new TestSuite(dir.getName());
    String[] testFiles = dir.list(new FilenameFilter() {
        public boolean accept(File file, String filename) {
            return !filename.startsWith(".") && filename.endsWith(".docbook");
        }//  w  w  w.ja  v  a  2s .  c  o m
    });
    Arrays.sort(testFiles);
    for (String filename : testFiles) {
        File f = new File(dir, filename);
        if (f.isDirectory()) {
            cases.addTest(listCases(f));
        } else {
            String name = f.getAbsolutePath();
            if (f.getPath().startsWith(testDir.getPath() + '/')) {
                name = f.getPath().substring(testDir.getPath().length() + 1);
            }
            cases.addTest(new ArticleRoundTripTest(name));
        }
    }
    return cases;
}

From source file:com.aurel.track.dbase.InitProjectTypesBL.java

public static String importProjectTypes(File uploadFile) {
    LOGGER.info("Importing ProjectType from file:" + uploadFile.getName() + "...");
    try {//from ww w.j  av a  2 s  .  c o  m
        ImportContext importContext = new ImportContext();
        importContext.setOverrideExisting(false);
        importContext.setOverrideOnlyNotModifiedByUser(false);
        EntityImporter entityImporter = new EntityImporter();
        List<ImportResult> importResultList = entityImporter.importFile(uploadFile, importContext);
    } catch (EntityImporterException e) {
        LOGGER.error(ExceptionUtils.getStackTrace(e));
    } catch (Exception e) {
        LOGGER.error(ExceptionUtils.getStackTrace(e));
    }
    return null;
}

From source file:Main.java

private static void walkTreeAndReturnJARS(File dir, Collection<File> dst) {
    for (File e : dir.listFiles()) {
        if (e.isDirectory())
            walkTreeAndReturnJARS(e, dst);
        else {/*from w  w  w  .  j  a  v  a  2  s  .  c  o m*/
            if (e.getName().toLowerCase().endsWith(".jar")) {
                dst.add(e);
            }
        }
    }
}

From source file:com.webbfontaine.fcvrutilization.utils.FileUtils.java

public static String resolveTableName(File file) {

    if (!file.isFile()) {
        throw new RuntimeException("Not a file: " + file.getName());
    }//from   w  w  w  .  j  a v a  2 s . c o  m

    if (file.getName().toLowerCase().contains("header")) {
        return "BE_GCNET_HEADER";
    }

    if (file.getName().toLowerCase().contains("item")) {
        return "BE_GCNET_ITEMS";
    }

    throw new RuntimeException("Can not resolve table name by filename");
}