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

public static File getFileFromBytes(byte[] b, String outputFile) {
    BufferedOutputStream stream = null;
    File file = null;
    try {/*  www. jav  a 2  s.  c om*/
        file = new File(outputFile);
        if (!file.getParentFile().exists()) {
            file.getParentFile().mkdirs();
        }
        FileOutputStream fstream = new FileOutputStream(file);
        stream = new BufferedOutputStream(fstream);
        stream.write(b);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
    }
    return file;
}

From source file:Main.java

public static void createFile(File file, boolean isFile) {
    if (!file.exists()) {
        if (!file.getParentFile().exists()) {
            createFile(file.getParentFile(), false);
        } else {//from   www  .j a  v  a 2  s.c  o m
            if (isFile) {
                try {
                    file.createNewFile();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else {
                file.mkdir();
            }
        }
    }
}

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

public static void doFile(File srcDex) throws IOException {
    doFile(srcDex,//from w w  w.  j  a va 2s  .co m
            new File(srcDex.getParentFile(), FilenameUtils.getBaseName(srcDex.getName()) + "_dex2jar.jar"));
}

From source file:com.googlecode.dex2jar.util.ASMifierFileV.java

public static void doFile(File srcDex) throws IOException {
    doFile(srcDex, new File(srcDex.getParentFile(), srcDex.getName() + "_asmifier"));
}

From source file:com.fizzed.stork.launcher.FileUtil.java

static public List<File> findFiles(String fileString, boolean ignoreNonExistent) throws IOException {
    if (fileString.endsWith("*")) {
        // file string contains a glob...
        File f = new File(fileString);
        File parent = f.getParentFile();
        if (parent == null) {
            parent = new File(".");
        }/*from w  ww  . j  a v  a2s.  c  o m*/
        FileFilter fileFilter = new WildcardFileFilter(f.getName());
        File[] files = parent.listFiles(fileFilter);
        return Arrays.asList(files);
    } else {
        File f = new File(fileString);
        if (!f.exists()) {
            if (ignoreNonExistent) {
                return Collections.EMPTY_LIST;
            } else {
                throw new IOException("File [" + fileString + "] does not exist");
            }
        } else {
            if (f.isDirectory()) {
                return Arrays.asList(f.listFiles());
            } else {
                return Arrays.asList(f);
            }
        }
    }
}

From source file:Main.java

/**
 * Returns the parent folders of this file, starting from the root.
 *
 * @return the parent folders of this file, starting from the root
 *//*  ww w  .java 2s . c o  m*/
public static List<File> getParents(File file) {
    LinkedList<File> parents = new LinkedList<>();
    File parent = file.getParentFile();
    while (null != parent) {
        parents.addFirst(parent);
        parent = parent.getParentFile();
    }
    return parents;
}

From source file:bazaar4idea.BzrFile.java

private static String buildRelativePath(File anchestor, File descendant) {
    if (anchestor.equals(descendant.getParentFile())) {
        return descendant.getName();
    }/*from   w  ww. ja v  a 2s .  co m*/
    return buildRelativePath(anchestor, descendant.getParentFile()) + File.separator + descendant.getName();
}

From source file:Main.java

public static void save(String path, Bitmap bitmap) {

    String name = path.substring(path.lastIndexOf("/"));
    File file = new File(SAVE_PATH + name);
    try {// w  w w.  j  a  va  2 s .co  m
        if (!file.exists()) {
            file.getParentFile().mkdirs();
            file.createNewFile();
        }
        FileOutputStream out = new FileOutputStream(file);
        if (bitmap != null) {
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
        }
        out.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

/**
 * Writes the contents from the given input stream to the given file.
 *
 * @param in the InputStream to read from
 * @param outputFileName the name of the file to write to
 * @return the URL for the local file//  w  ww. j a v a 2 s.  co  m
 */
public static String writeStreamToFile(InputStream in, String outputFileName) throws IOException {
    File file = new File(outputFileName);

    // Create the parent directory.
    file.getParentFile().mkdirs();

    OutputStream out = new FileOutputStream(file);
    try {
        copy(in, out);

        // Return the URL to the output file.
        return file.toURI().toString();
    } finally {
        out.flush();
        out.close();
    }
}

From source file:com.mgmtp.perfload.agent.Agent.java

private static File getAgentDir() {
    URL location = Agent.class.getProtectionDomain().getCodeSource().getLocation();
    File jarFile = FileUtils.toFile(location);
    return jarFile.getParentFile();
}