Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8453615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:48:48+00:00 2026-06-10T11:48:48+00:00

I was unable to understand the following file constructors. public File(String parent, String child)

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:48:49+00:00Added an answer on June 10, 2026 at 11:48 am

    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.


    Examples

    Consider the following partial file system:

    Documents
        Homework
        Classwork
        Tests
    

    Rather than declaring each new file with “Documents\Subdir”, you can declare the Documents directory as a file, and use it as the parent File of the other File instances, like so:

    File documents = new File("Documents");
    File tests = new File("Documents/Tests"); // new File(String);
    
    File homework = new File(documents, "Homework"); // new File(File, String)
    
    File classwork = new File("Documents", "Classwork"); // new File(String, String)
    

    Real-world application

    In my experience, I’ve used applications that provide an API containing a method that returns the directory file in which third-party “plugins” are allowed to save/read files. Without the File(File, String) constructor, I would need to convert the directory file into an absolute path and append my target file to it.

    In the following example, Environment.getProgramDirectory() returns the directory file in which permissions are granted.

    File settingsFile = new File(Environment.getProgramDirectory(), "settings.txt");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Myself and some teammates have been unable to understand why the following snippet of
I am unable to understand the following text... Does it mean that <clinit> is
Iam unable to understand following: $this->db->select('1', FALSE); Can some one elaborate it in simple
I am having following code but unable to understand as to why no match
I am unable to understand the weird behavior of this program. I have 2
I have the following procedure private static IMyInterface OpenInstance( string assemblyPath, string classType, string
I'm unable to understand the following codes $(this).animate({rotate3Di: degrees}, options) . Here rotate3Di is
I have the following script, which works successfully till the last file slice is
Static variable has file scope. Say I have two following files: file1.h file1.cpp file2.h
I am unable to understand the weird behaviour of the program. It throws a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.