3:30 am - Friday May 26, 2017

To get parent of the file using getParent() method

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

                                                   This tutorial explains how To get parent of the file using getParent() method,The java.io.File.getParent() method returns the pathname string if this abstract path name’s parent or null if this pathname does not name a parent directory.

import java.io.File;</p>
public class GetParent

{

public static void main(String[] args)

{

File file = new File("/home/mathan/Pictures/rest.txt");

if (!file.exists())

{

file = file.getParentFile();

}

System.out.println(file);

}

}

Output

 /home/mathan/Pictures

BACK

Filed in: Java Examples

Comments are closed.