Page 1 of 1

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

Posted: Fri Mar 20, 2015 1:37 am
by pfilaretov
Option 3: "You can create files in any directory using File class's API."
You can create files in any directory if you have rights for that, isn't it?

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

Posted: Fri Mar 20, 2015 3:37 am
by admin
Yes, you will need to assume that such things are in order. Otherwise, there are a lot of dependencies and a question will not be able to list all. For example, if there is free disk space, and if the disk is writable, and if the directory doesn't contain a file by the same name already.

HTH,
Paul.

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

Posted: Mon Mar 23, 2015 12:39 am
by pfilaretov
I see, thx, Paul

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

Posted: Wed Jun 22, 2016 7:23 am
by dieterdde
Hello,

option #4:

//assume that test.txt exists, and hmm.txt does not:

File f = new File("test.txt");
Files.move(f.toPath(),new File("hmm.txt").toPath());
System.out.printf("%s - %b", f, Files.exists(Paths.get("hmm.txt")));
--> test.txt - true

In any case, if one would argue that i should restrict my argument only to java.io.File, even then you can use renameTo(), whilst it won't change the original file object (ref var will point to a new file object and the other one will be garbage collected i assume), it will still change the underlying path!

Option #4 does not say anything that we can't change the File object instances, it only talks about changing the underlying, whether that underlying is represented by an instance of Path, File or whatever shouldn't matter.

Cheers,
Dieter