Skip to content
Advertisement

Do java.io.File(String parent, String child) and java.io.File(String pathname) do the same work?

I’ve read Oracle documentation, but I still don’t get it. For example:

JavaScript

and

JavaScript

Are they the same in this case?

Advertisement

Answer

So taken from the OpenJDK 8(https://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/share/classes/java/io/File.java) the code the the one String Constructor is:

JavaScript

and for the two String Constructor is:

JavaScript

where normalize just removes stuff like . and .. So you may see that parent and child do an additional call to the file system. But the call only means “Give me the path to child if the path is realative to parent”. So in your call they will result in the same behavior.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement