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.scooter1556.sms.server.utilities.DatabaseUtils.java

public static int getDatabaseVersion(String db) {
    File[] files = getDatabaseFiles(db);

    if (files == null) {
        return -1;
    }/*from ww  w .j a  v a  2s  . c o  m*/

    // Check we found the database file
    if (files.length == 0) {
        return -1;
    }

    // Extract database version
    int version = 0;

    for (File file : files) {
        int v = Integer.valueOf(file.getName().split("\\.")[1]);

        if (v > version) {
            version = v;
        }
    }

    return version;
}

From source file:MakeDirectories.java

private static void fileData(File f) {
    System.out.println("Absolute path: " + f.getAbsolutePath() + "\n Can read: " + f.canRead()
            + "\n Can write: " + f.canWrite() + "\n getName: " + f.getName() + "\n getParent: " + f.getParent()
            + "\n getPath: " + f.getPath() + "\n length: " + f.length() + "\n lastModified: "
            + f.lastModified());//from w w w  .java 2 s.com
    if (f.isFile())
        System.out.println("It's a file");
    else if (f.isDirectory())
        System.out.println("It's a directory");
}

From source file:com.gargoylesoftware.htmlunit.WebDriverOldTestsTest.java

/**
 * Provides the data, i.e. the files on which the tests should run.
 * TODO: use a dedicated test runner instead of this parameterized runner.
 * @return the tests files on which to run the tests
 *//* w  w  w  .  ja v  a2  s .c  o m*/
@org.junit.runners.Parameterized.Parameters
public static Collection<File[]> data() {
    final File testsDir = new File("target/generated_tests");
    final List<File[]> response = new ArrayList<File[]>();

    if (testsDir.exists()) {
        final File[] testFiles = testsDir.listFiles(new FileFilter() {
            public boolean accept(final File pathname) {
                final String name = pathname.getName();
                return (name.endsWith(".html.expected") || name.endsWith(".html.FF3.expected"));
            }
        });

        for (final File f : testFiles) {
            response.add(new File[] { f });
        }
    }
    LOG.info(response.size() + " tests found in folder " + testsDir);
    return response;
}

From source file:net.mitnet.tools.pdf.book.io.FileNameHelper.java

public static String rewriteFileNameSuffix(File sourceFile, String newFileNameSuffix,
        String newFileNameExtension) {
    String newFileName = rewriteFileNameSuffix(sourceFile.getName(), newFileNameSuffix, newFileNameExtension);
    return newFileName;
}

From source file:com.schnobosoft.semeval.cortical.SemEvalTextSimilarity.java

/**
 * Read an input file of tab-separated texts. Ignoring empty lines.
 *
 * @param inputFile the input {@link File}
 * @return an array {@link CompareModels}, each holding two {@link Text}s which have been read from the file.
 * @throws IOException//from w w w  .j  a v a  2  s  .  co m
 */
private static CompareModels[] readInput(File inputFile) throws IOException {
    LOG.info("Reading input file " + inputFile);
    assert inputFile.getName().startsWith(INPUT_FILE_PREFIX);
    List<CompareModels> lines = Files.lines(inputFile.toPath()).filter((s) -> !s.isEmpty())
            .map(line -> line.split("\t")).map(line -> new CompareModels(new Text(line[0]), new Text(line[1])))
            .collect(Collectors.toList());
    return lines.toArray(new CompareModels[lines.size()]);
}

From source file:cc.kave.commons.externalserializationtests.ExternalTestCaseProvider.java

private static List<TestCase[]> getTestCasesInCurrentFolder(File currentDirectory, String rootPrefix)
        throws ClassNotFoundException, IOException {
    List<TestCase[]> testCases = new LinkedList<TestCase[]>();

    Class<?> serializedType = Object.class;
    String expectedCompact = null;
    String expectedFormatted = null;

    for (File file : currentDirectory.listFiles()) {
        if (file.getName().equals(settingsFile)) {
            String className;// w ww.  j  a  v a 2  s  .co m
            className = TestSettingsReader.readSection(file, "Java").get(ExternalTestSetting.SerializedType);
            serializedType = Class.forName(className);
        }

        if (file.getName().equals(expectedCompactFile)) {
            expectedCompact = new String(Files.readAllBytes(file.toPath()));
        }

        if (file.getName().equals(expectedFormattedFile)) {
            expectedFormatted = new String(Files.readAllBytes(file.toPath()));
        }
    }

    if (expectedCompact == null) {
        return new LinkedList<TestCase[]>();
    }

    for (File file : currentDirectory.listFiles()) {
        boolean isInputFile = !file.getName().equals(settingsFile)
                && !file.getName().equals(expectedCompactFile) && !file.getName().equals(expectedFormattedFile);
        if (!isInputFile) {
            continue;
        }

        String input = new String(Files.readAllBytes(file.toPath()));
        testCases.add(new TestCase[] { new TestCase(getTestCaseName(file.getAbsolutePath(), rootPrefix),
                serializedType, input, expectedCompact, expectedFormatted) });
    }

    return testCases;
}

From source file:com.idega.util.FileLocalizer.java

public static void findRecursive(File fileToRead, Properties props) {
    if (fileToRead.isDirectory()) {
        int index = fileToRead.getName().toUpperCase().indexOf("CVS");
        File[] F = fileToRead.listFiles();
        if (index == -1) {
            for (int i = 0; i < F.length; i++) {
                findRecursive(F[i], props);
            }//from   w  w w .j  a va 2s  .  c  om
        }
    } else if (fileToRead.isFile()) {
        int index = fileToRead.getName().toUpperCase().indexOf(".JAVA");
        if (index != -1) {
            readFile(fileToRead, props);
        }
    } else {
        return;
    }
}

From source file:Main.java

private static void searchDirSort(File dirFile) {
    File[] files = dirFile.listFiles();
    List<File> dirList = new ArrayList<File>();
    if (files != null) {
        for (File file : files) {
            if (file.isDirectory()) {
                dirList.add(file);/*from  www. j a v  a2  s  . c  om*/
            } else {
                if (file.getName().toLowerCase().contains(fileType.toLowerCase())) {
                    listFile.add(file);
                }
            }
        }
        for (File dir : dirList) {
            if (dir.getName().subSequence(0, 1).equals(".") || dir.getName().equals("Android")) {

            } else {
                searchDirSort(dir);
            }
        }
    }
}

From source file:bazaar4idea.BzrFile.java

private static String buildRelativePath(File anchestor, File descendant) {
    if (anchestor.equals(descendant.getParentFile())) {
        return descendant.getName();
    }//from   w w w  .  j a va 2  s .  c  om
    return buildRelativePath(anchestor, descendant.getParentFile()) + File.separator + descendant.getName();
}