Page 1 of 1

About Question enthuware.ocpjp.v7.2.1214 :

Posted: Sun Sep 22, 2013 9:36 am
by The_Nick
RESOLVED.

Hi,
So basically in short p1 must be the same as p2 in order to return true.
The name is quite confusing as it says startsWith, one would expect to check only the beginning
Forget about it checks only N elements belonging to the other path (the one passed as argument)
Thanks.

The_Nick.

Re: About Question enthuware.ocpjp.v7.2.1214 :

Posted: Sat Jan 04, 2025 6:50 am
by user_m1k0
Output under Linux:

Code: Select all

\temp\records/clients.dat false
java --version
openjdk 21.0.5 2024-10-15
OpenJDK Runtime Environment (Red_Hat-21.0.5.0.11-1) (build 21.0.5+11)
OpenJDK 64-Bit Server VM (Red_Hat-21.0.5.0.11-1) (build 21.0.5+11, mixed mode, sharing)

improved code:

Code: Select all

public static void writeData() {
        // var p1 = Paths.get("\\temp\\records");
        // var p2 = p1.resolve("clients.dat");
        var p1 = Paths.get("temp", "records");
        var p2 = p1.resolve("clients.dat");
        System.out.println(p2 + " " + isValid(p2));
    }