File Constructors Explanation

I was unable to understand the following file constructors.

public File(String parent, String child) and 
public File(File parent, String child)

What do the parameters parent and child mean for the file? When can I use these? I have done few programs related to file but I have never used these. I usually use

public File(String pathname)

I have read Javadoc but I could not figure out when and how to use these constructors. Could someone please explain and give examples.

2

4 Answers

Explanation

The parent parameter is the parent directory of the child file name or relative file path.

Where parent is a File instance, it is a directory file. Where parent is a String, it's simply that directory in pathname terms.


Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.