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 String showOpenFile(String currentDirectoryPath, Component parent, final String filterRegex,
        final String filterDescription) {
    JFileChooser fileChooser = new JFileChooser(currentDirectoryPath);
    fileChooser.addChoosableFileFilter(new FileFilter() {
        private Pattern regexPattern = Pattern.compile(filterRegex);

        public boolean accept(File f) {
            if (f.isDirectory())
                return true;
            return regexPattern.matcher(f.getName()).matches();
        }/*  w ww .  j a  v  a 2s . c  o  m*/

        public String getDescription() {
            return filterDescription;
        }

    });
    fileChooser.showOpenDialog(parent);

    File choosedFile = fileChooser.getSelectedFile();
    if (choosedFile == null)
        return null;
    return choosedFile.getAbsolutePath();
}

From source file:Main.java

private static void dumpFolderRecursive(final File folder, final StringBuilder sb, final int level) {
    for (int i = 0; i < level; i++)
        sb.append("\t");
    sb.append(folder.getName());
    sb.append("\n");
    for (File file : folder.listFiles()) {
        if (file.isDirectory())
            dumpFolderRecursive(file, sb, level + 1);
        else {//from w w w  . j a v a  2  s  . co  m
            for (int i = 0; i <= level; i++)
                sb.append("\t");
            sb.append(file.getName());
            sb.append("\n");
        }
    }
}

From source file:com.opensearchserver.hadse.index.IndexCatalog.java

public final static void loadAll() {
    if (Hadse.data_dir == null)
        return;// w  w w .ja  va  2s  . c  o m
    if (!(Hadse.data_dir.isDirectory()))
        return;
    File[] indexList = Hadse.data_dir.listFiles((FileFilter) DirectoryFileFilter.INSTANCE);
    if (indexList == null)
        return;
    for (File indexDirectory : indexList) {
        IndexItem indexItem = IndexItem.get(indexDirectory.getName());
        indexItem.load();
    }
}

From source file:com.gargoylesoftware.js.CodeUpdater.java

private static void process(final File dir, final boolean isMain) throws IOException {
    for (final File file : dir.listFiles()) {
        if (file.isDirectory()) {
            process(file, isMain);/*from  ww  w  .  ja  v a2 s  .c o m*/
        } else if (file.getName().endsWith(".java") && !file.getName().equals("package-info.java")) {
            processFile(file, isMain);
        }
    }
}

From source file:com.phoenixnap.oss.ramlapisync.plugin.ClassLoaderUtils.java

public static List<String> loadClasses(MavenProject mavenProject) throws MojoExecutionException {

    List<String> classes = Lists.newArrayList();

    File rootDir = new File(mavenProject.getBuild().getSourceDirectory());
    Collection<File> files = FileUtils.listFiles(rootDir, new SuffixFileFilter(".java"), TrueFileFilter.TRUE);
    for (File file : files) {
        String clazz = file.getName().replace(".java", "");
        if (!clazz.isEmpty()) {
            classes.add(clazz);//from   ww w .j ava  2 s  .  co  m
        }
    }
    return classes;
}

From source file:com.ttech.cordovabuild.infrastructure.archive.ArchiveUtils.java

private static void addFileToTarGz(TarArchiveOutputStream tOut, Path path, String base) throws IOException {
    File f = path.toFile();
    String entryName = base + f.getName();
    TarArchiveEntry tarEntry = new TarArchiveEntry(f, entryName);
    tOut.putArchiveEntry(tarEntry);/*from w w w.  ja v  a 2s . c  o m*/
    if (f.isFile()) {
        IOUtils.copy(new FileInputStream(f), tOut);
        tOut.closeArchiveEntry();
    } else {
        tOut.closeArchiveEntry();
        File[] children = f.listFiles();
        if (children != null) {
            for (File child : children) {
                addFileToTarGz(tOut, child.toPath().toAbsolutePath(), entryName + "/");
            }
        }
    }
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.evaluation.GenerateCrossDomainCVReport.java

/**
 * Merges id2outcome files from sub-folders with cross-domain and creates a new folder
 * with overall results/*from w  w w  .  j a va  2s .  c  om*/
 *
 * @param folder folder
 * @throws java.io.IOException
 */
public static void aggregateDomainResults(File folder, String subDirPrefix, final String taskFolderSubText,
        String outputFolderName) throws IOException {
    // list all sub-folders
    File[] folders = folder.listFiles(new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return pathname.isDirectory() && pathname.getName().contains(taskFolderSubText);
        }
    });

    if (folders.length == 0) {
        throw new IllegalArgumentException("No sub-folders 'SVMHMMTestTask*' found in " + folder);
    }

    // write to a file
    File outFolder = new File(folder, outputFolderName);
    File output = new File(outFolder, subDirPrefix);
    output.mkdirs();

    File outCsv = new File(output, TOKEN_LEVEL_PREDICTIONS_CSV);

    CSVPrinter csvPrinter = new CSVPrinter(new FileWriter(outCsv), SVMHMMUtils.CSV_FORMAT);
    csvPrinter.printComment(SVMHMMUtils.CSV_COMMENT);

    ConfusionMatrix cm = new ConfusionMatrix();

    for (File domain : folders) {
        File tokenLevelPredictionsCsv = new File(domain, subDirPrefix + "/" + TOKEN_LEVEL_PREDICTIONS_CSV);

        if (!tokenLevelPredictionsCsv.exists()) {
            throw new IllegalArgumentException(
                    "Cannot locate tokenLevelPredictions.csv: " + tokenLevelPredictionsCsv);
        }

        CSVParser csvParser = new CSVParser(new FileReader(tokenLevelPredictionsCsv),
                CSVFormat.DEFAULT.withCommentMarker('#'));

        for (CSVRecord csvRecord : csvParser) {
            // copy record
            csvPrinter.printRecord(csvRecord);

            // update confusion matrix
            cm.increaseValue(csvRecord.get(0), csvRecord.get(1));
        }
    }

    // write to file
    FileUtils.writeStringToFile(new File(outFolder, "confusionMatrix.txt"), cm.toString() + "\n"
            + cm.printNiceResults() + "\n" + cm.printLabelPrecRecFm() + "\n" + cm.printClassDistributionGold());

    // write csv
    IOUtils.closeQuietly(csvPrinter);
}

From source file:IO.Files.java

/**
 * Returns true if the given file is successfully moved to the destination
 * folder//  www  .ja v a2  s  .  c  o  m
 *
 * @param file source file
 * @param subFolderName the name of the subfolder to create and move the
 * file to
 * @return true if the given file is successfully moved to the destination
 * folder
 */
public static boolean MoveFileToSubFolder(File file, String subFolderName) {
    String filename = file.getName();
    File destinationFolder = new File(file.getParent() + "\\" + subFolderName);
    String destinationFilePath = destinationFolder + "\\" + filename;

    if (!destinationFolder.exists()) {
        destinationFolder.mkdir();
    }

    if (file.renameTo(new File(destinationFilePath))) {
        //System.out.println(String.format("File '%s' is moved successful to folder:\n%s\n", filename, destinationFolder));
        return true;
    } else {
        //System.out.println(String.format("File '%s' is failed to move to folder: \n%s\n", filename, destinationFolder));
        return false;
    }
}

From source file:Main.java

public static Collection<File> listFiles(File directory, String suffix) {
    final String _suffix = "." + suffix;
    FileFilter filter = new FileFilter() {
        @Override//from   w  w  w . ja  v  a 2  s  . com
        public boolean accept(File file) {
            if (file.isDirectory())
                return true;
            String name = file.getName();
            int endLen = _suffix.length();
            if (name.regionMatches(true, name.length() - endLen, _suffix, 0, endLen)) {
                return true;
            }
            return false;
        }
    };
    if (!directory.isDirectory()) {
        throw new IllegalArgumentException("Parameter 'directory' is not a directory");
    }

    if (filter == null) {
        throw new NullPointerException("Parameter 'fileFilter' is null");
    }
    Collection<File> files = new LinkedList<File>();
    innerListFiles(files, directory, filter);
    return files;
}

From source file:Main.java

static void zipDir(File zipDir, ZipOutputStream zos, String name) throws IOException {
    // Create a new File object based on the directory we have to zip
    if (name.endsWith(File.separator))
        name = name.substring(0, name.length() - File.separator.length());
    if (!name.endsWith(ZIP_FILE_SEPARATOR))
        name = name + ZIP_FILE_SEPARATOR;

    // Place the zip entry in the ZipOutputStream object

    // Get a listing of the directory content
    File[] dirList = zipDir.listFiles();
    if (dirList.length == 0) { // empty directory
        if (DEBUG)
            System.out.println("Add empty entry for directory : " + name);
        ZipEntry anEntry = new ZipEntry(name);
        zos.putNextEntry(anEntry);//from ww w .  ja va 2s  .co m
        return;
    }

    // Loop through dirList, and zip the files
    for (int i = 0; i < dirList.length; i++) {
        File f = dirList[i];
        String fName = name + f.getName();
        if (f.isDirectory()) {
            // if the File object is a directory, call this
            // function again to add its content recursively
            zipDir(f, zos, fName);
        } else {
            zipFile(f, zos, fName);
        }
    }
    return;
}