Example usage for java.io File getParent

List of usage examples for java.io File getParent

Introduction

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

Prototype

public String getParent() 

Source Link

Document

Returns the pathname string 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.getParent());

}

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[] args) {
    File file = new File("C:/File/demo.txt");
    String strParentDirectory = file.getParent();
    System.out.println("Parent directory is : " + strParentDirectory);
}

From source file:Main.java

public static void main(String[] args) {
    File file = new File("C:/demo.txt");
    System.out.println("Parent directory:" + file.getParent());
}

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   ww  w .  j a  va 2  s .c  om
    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:JFileChooserSelectionOption.java

public static void main(String[] a) {
    JFileChooser fileChooser = new JFileChooser(".");
    int status = fileChooser.showOpenDialog(null);

    if (status == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fileChooser.getSelectedFile();
        System.out.println(selectedFile.getParent());
        System.out.println(selectedFile.getName());
    } else if (status == JFileChooser.CANCEL_OPTION) {
        System.out.println("canceled");
    }// w  ww  .  j  a  v  a 2 s  .c  o m
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    ZipInputStream zipinputstream = new ZipInputStream(new FileInputStream("filename"));
    ZipEntry zipentry = zipinputstream.getNextEntry();
    while (zipentry != null) {
        String entryName = zipentry.getName();
        File newFile = new File(entryName);
        String directory = newFile.getParent();
        if (directory == null) {
            if (newFile.isDirectory())
                break;
        }//from   w  w w  .  java  2  s  .  co m
        RandomAccessFile rf = new RandomAccessFile(entryName, "r");
        String line;
        if ((line = rf.readLine()) != null) {
            System.out.println(line);
        }
        rf.close();
        zipinputstream.closeEntry();
        zipentry = zipinputstream.getNextEntry();
    }
    zipinputstream.close();
}

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.getParent());
    System.out.println(myFile);//from www  .j  a v a  2 s .c om
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String destinationname = "d:\\";
    byte[] buf = new byte[1024];
    ZipInputStream zipinputstream = null;
    ZipEntry zipentry;/*from w w w .  j  a  va2s .c o m*/
    zipinputstream = new ZipInputStream(new FileInputStream("fileName"));
    zipentry = zipinputstream.getNextEntry();
    while (zipentry != null) {
        String entryName = zipentry.getName();
        FileOutputStream fileoutputstream;
        File newFile = new File(entryName);
        String directory = newFile.getParent();

        if (directory == null) {
            if (newFile.isDirectory())
                break;
        }
        fileoutputstream = new FileOutputStream(destinationname + entryName);
        int n;
        while ((n = zipinputstream.read(buf, 0, 1024)) > -1) {
            fileoutputstream.write(buf, 0, n);
        }
        fileoutputstream.close();
        zipinputstream.closeEntry();
        zipentry = zipinputstream.getNextEntry();
    }
    zipinputstream.close();
}

From source file:MainClass.java

public static void main(String[] a) {
    JFileChooser fileChooser = new JFileChooser(".");
    fileChooser.setAccessory(new LabelAccessory(fileChooser));
    int status = fileChooser.showOpenDialog(null);
    if (status == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fileChooser.getSelectedFile();
        System.out.println(selectedFile.getParent());
        System.out.println(selectedFile.getName());
    } else if (status == JFileChooser.CANCEL_OPTION) {
        System.out.println("JFileChooser.CANCEL_OPTION");
    }//from   w  w  w . j a  v a2 s .  co m
}