Java IO Tutorial - Java File.getParent()








Syntax

File.getParent() has the following syntax.

public String getParent()

Example

In the following code shows how to use File.getParent() method.

/*from   w w w .java2 s .co m*/

import java.io.File;

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

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


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

  }
}

The code above generates the following result.