File Constructors Explanation

前端 未结 4 595
轮回少年
轮回少年 2021-02-05 06:23

I was unable to understand the following file constructors.

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

4条回答
  •  北海茫月
    2021-02-05 07:28

    Let's explain with some examples:

    Assuming that you have the following structure:

    /dir1
      dir11
    

    The constructor that you usually use new File("/dir1/dir11") is equivalent to

    new File("/dir1", "dir11") (constructor taking 2 String as arguments)

    and also equivalent to

    new File(new File("/dir1"), "dir11") (constructor using a File as first argument).

提交回复
热议问题