Example usage for java.io File getParentFile

List of usage examples for java.io File getParentFile

Introduction

In this page you can find the example usage for java.io File getParentFile.

Prototype

public File getParentFile() 

Source Link

Document

Returns the abstract pathname of this abstract pathname's parent, or null if this pathname does not name a parent directory.

Usage

From source file:Main.java

License:asdf

public static void main(String[] args) throws Exception {

    // create new files
    File f = new File("c:/asdf/");

    System.out.print(f.getParentFile());

}

From source file:Main.java

public static void main(String[] args) {
    File file = new File("C:/demo.txt");
    File fileParent = file.getParentFile();

    System.out.println("Parent directory: " + fileParent.getPath());
}

From source file:MainClass.java

public static void main(String[] a) {
    File myFile = new File("C:" + File.separator + "jdk1.5.0" + File.separator, "File.java");
    System.out.println(myFile.getParentFile());
    System.out.println(myFile);// w ww .  j  a v a  2 s .  c o  m
}

From source file:MainClass.java

public static void main(String[] a) {

    File myFile = new File("C:" + File.separator + "jdk1.5.0" + File.separator, "File.java");

    System.out.println(myFile.getParentFile());
    System.out.println(myFile);//from w w w.java 2  s. c om
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    File file = new File("test.java");
    String parentPath = file.getParent();
    System.out.println(parentPath);
    File parentDir = file.getParentFile();

    System.out.println(parentDir);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    File file = new File("D:\\test\\test.java");
    String parentPath = file.getParent();
    System.out.println(parentPath);
    File parentDir = file.getParentFile();
    System.out.println(parentDir);

    parentPath = parentDir.getParent();/*from   w w  w.j a v a2s.  c  o m*/
    System.out.println(parentPath);
    parentDir = parentDir.getParentFile();
    System.out.println(parentDir);

    parentPath = parentDir.getParent();
    System.out.println(parentPath);
    parentDir = parentDir.getParentFile();
    System.out.println(parentDir);
}

From source file:com.doculibre.constellio.utils.resources.WriteResourceBundleUtils.java

@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
    File binDir = ClasspathUtils.getClassesDir();
    File projectDir = binDir.getParentFile();
    File sourceDir = new File(projectDir, "source");

    String defaultLanguage;/*from w  ww. j ava  2 s  . c o m*/
    String otherLanguage;
    if (args.length > 0) {
        defaultLanguage = args[0];
        otherLanguage = args[1];
    } else {
        defaultLanguage = Locale.ENGLISH.getLanguage();
        otherLanguage = Locale.FRENCH.getLanguage();
    }

    List<File> propertiesFiles = (List<File>) FileUtils.listFiles(sourceDir, new String[] { "properties" },
            true);
    for (File propertiesFile : propertiesFiles) {
        File propertiesDir = propertiesFile.getParentFile();

        String propertiesNameWoutSuffix = StringUtils.substringBefore(propertiesFile.getName(), "_");
        propertiesNameWoutSuffix = StringUtils.substringBefore(propertiesNameWoutSuffix, ".properties");

        String noLanguageFileName = propertiesNameWoutSuffix + ".properties";
        String defaultLanguageFileName = propertiesNameWoutSuffix + "_" + defaultLanguage + ".properties";
        String otherLanguageFileName = propertiesNameWoutSuffix + "_" + otherLanguage + ".properties";

        File noLanguageFile = new File(propertiesDir, noLanguageFileName);
        File defaultLanguageFile = new File(propertiesDir, defaultLanguageFileName);
        File otherLanguageFile = new File(propertiesDir, otherLanguageFileName);

        if (defaultLanguageFile.exists() && otherLanguageFile.exists() && !noLanguageFile.exists()) {
            System.out.println(defaultLanguageFile.getPath() + " > " + noLanguageFileName);
            System.out.println(defaultLanguageFile.getPath() + " > empty file");

            defaultLanguageFile.renameTo(noLanguageFile);
            FileWriter defaultLanguageEmptyFileWriter = new FileWriter(defaultLanguageFile);
            defaultLanguageEmptyFileWriter.write("");
            IOUtils.closeQuietly(defaultLanguageEmptyFileWriter);
        }
    }
}

From source file:com.googlecode.dex2jar.v3.Main.java

public static void main(String... args) {
    System.err.println("this cmd is deprecated, use the d2j-dex2jar if possible");
    System.out.println("dex2jar version: translator-" + Main.class.getPackage().getImplementationVersion());
    if (args.length == 0) {
        System.err.println("dex2jar file1.dexORapk file2.dexORapk ...");
        return;/*from   ww  w. j  av  a 2  s.c o  m*/
    }
    String jreVersion = System.getProperty("java.specification.version");
    if (jreVersion.compareTo("1.6") < 0) {
        System.err.println("A JRE version >=1.6 is required");
        return;
    }

    boolean containsError = false;

    for (String file : args) {
        File dex = new File(file);
        final File gen = new File(dex.getParentFile(), FilenameUtils.getBaseName(file) + "_dex2jar.jar");
        System.out.println("dex2jar " + dex + " -> " + gen);
        try {
            doFile(dex, gen);
        } catch (Exception e) {
            containsError = true;
            niceExceptionMessage(new DexException(e, "while process file: [%s]", dex), 0);
        }
    }
    System.out.println("Done.");
    System.exit(containsError ? -1 : 0);
}

From source file:ee.ria.xroad.asyncdb.AsyncDBMemoryUsageTest.java

/**
 * @param args - arguments of main method, here not used.
 * @throws Exception - thrown when memory usage test fails.
 *///from w w  w  . ja v a2s.c o  m
public static void main(String[] args) throws Exception {
    File logDir = null;

    try {
        SoapMessageImpl requestMessage = AsyncDBTestUtil.getFirstSoapRequest();
        File logFile = new File(AsyncDBTestUtil.getAsyncLogFilePath());
        logDir = logFile.getParentFile();

        long previousFreeFileDescriptorCount = 0;
        boolean first = true;

        for (int i = 0; i < ITERATIONS; i++) {
            LOG.info("Adding request number {}...", i);

            WritingCtx writingCtx = QUEUE.startWriting();
            writingCtx.getConsumer().soap(requestMessage);
            writingCtx.commit();

            long freeFileDescriptorCount = SystemMetrics.getFreeFileDescriptorCount();
            LOG.info("Free file descriptor count: {}", freeFileDescriptorCount);

            if (!first && freeFileDescriptorCount < previousFreeFileDescriptorCount) {
                throw new RuntimeException("File descriptor count must not increase as requests are added!");
            }

            previousFreeFileDescriptorCount = freeFileDescriptorCount;
            first = false;
        }

        LOG.info("Async DB memory usage test accomplished successfully");
    } finally {
        FileUtils.deleteDirectory(new File(AsyncDBTestUtil.getProviderDirPath()));

        if (logDir != null) {
            FileUtils.deleteDirectory(logDir);
        }
    }
}

From source file:com.doculibre.constellio.utils.license.ApplyLicenseUtils.java

/**
 * @param args/*from  www. j  a  va2  s.  c o  m*/
 */
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
    URL licenceHeaderURL = ApplyLicenseUtils.class.getResource("LICENSE_HEADER");
    File binDir = ClasspathUtils.getClassesDir();
    File projectDir = binDir.getParentFile();
    //        File dryrunDir = new File(projectDir, "dryrun");
    File licenceFile = new File(licenceHeaderURL.toURI());
    List<String> licenceLines = readLines(licenceFile);
    //        for (int i = 0; i < licenceLines.size(); i++) {
    //            String licenceLine = licenceLines.get(i);
    //            licenceLines.set(i, " * " + licenceLine);
    //        }
    //        licenceLines.add(0, "/**");
    //        licenceLines.add(" */");

    List<File> javaFiles = (List<File>) org.apache.commons.io.FileUtils.listFiles(projectDir,
            new String[] { "java" }, true);
    for (File javaFile : javaFiles) {
        if (isValidPackage(javaFile)) {
            List<String> javaFileLines = readLines(javaFile);
            if (!javaFileLines.isEmpty()) {
                boolean modified = false;
                String firstLineTrim = javaFileLines.get(0).trim();
                if (firstLineTrim.startsWith("package")) {
                    modified = true;
                    javaFileLines.addAll(0, licenceLines);
                } else if (firstLineTrim.startsWith("/**")) {
                    int indexOfEndCommentLine = -1;
                    loop2: for (int i = 0; i < javaFileLines.size(); i++) {
                        String javaFileLine = javaFileLines.get(i);
                        if (javaFileLine.indexOf("*/") != -1) {
                            indexOfEndCommentLine = i;
                            break loop2;
                        }
                    }
                    if (indexOfEndCommentLine != -1) {
                        modified = true;
                        int i = 0;
                        loop3: for (Iterator<String> it = javaFileLines.iterator(); it.hasNext();) {
                            it.next();
                            if (i <= indexOfEndCommentLine) {
                                it.remove();
                            } else {
                                break loop3;
                            }
                            i++;
                        }
                        javaFileLines.addAll(0, licenceLines);
                    } else {
                        throw new RuntimeException(
                                "Missing end comment for file " + javaFile.getAbsolutePath());
                    }
                }

                if (modified) {
                    //                        String outputFilePath = javaFile.getPath().substring(projectDir.getPath().length());
                    //                        File outputFile = new File(dryrunDir, outputFilePath);
                    //                        outputFile.getParentFile().mkdirs();
                    //                        System.out.println(outputFile.getPath());
                    //                        FileOutputStream fos = new FileOutputStream(outputFile);
                    System.out.println(javaFile.getPath());
                    FileOutputStream fos = new FileOutputStream(javaFile);
                    IOUtils.writeLines(javaFileLines, "\n", fos);
                    IOUtils.closeQuietly(fos);
                }
            }
        }
    }
}