The second example moves the addresses.txt file from the directory user to the directory zoo-new, and it renames it to addresses2.txt.
OCA Java 6, OCP Java 6, OCP Java 8
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
OCA Java 6, OCP Java 6, OCP Java 8
OCA Java 6, OCP Java 6, OCP Java 8
OCA Java 6, OCP Java 6, OCP Java 8
T Vergilio wrote:1) What if the file had a bunch of commas in it? That's a non-empty file which would output nothing, making option E correct.
T Vergilio wrote:2) How about if it was a really large file and File.lines() got interrupted half way through reading it? It does, after all, read lazily. Let's say another application modified the file halfway through the process. Wouldn't it throw an IOException, making option A correct?
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
T Vergilio wrote:1) What if the file had a bunch of commas in it? That's a non-empty file which would output nothing, making option E correct.
T Vergilio wrote:2) How about if it was a really large file and File.lines() got interrupted half way through reading it? It does, after all, read lazily. Let's say another application modified the file halfway through the process. Wouldn't it throw an IOException, making option A correct?
T Vergilio wrote:Now I do have an issue with question 17 on page 502.
Files.walk() will search the root level and all other levels of the file tree, so options E and F are also possible outcomes of executing the code.
If the only place where there are .java files is inside the /animals/cute directory, for example, then E, F and G are all correct.
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
OCA Java 6, OCP Java 6, OCP Java 8
Method using it may throw an exception (...)
Methods using it may throw an exception (...)
OCA Java 6, OCP Java 6, OCP Java 8
By default, the move() method will follow links, throw an exception if the file already exists, and not perform an atomic move. These behaviours can be changed by providing the optional values NOFOLLOW_LINKS, REPLACE_EXISTING, or ATOMIC_MOVE, respectively, to the method.
If the file is a symbolic link then the symbolic link itself, not the target of the link, is moved.
This method takes a varargs argument – the following StandardCopyOption enums are supported:
REPLACE_EXISTING – Performs the move even when the target file already exists. If the target is a symbolic link, the symbolic link is replaced but what it points to is not affected.
ATOMIC_MOVE – Performs the move as an atomic file operation. If the file system does not support an atomic move, an exception is thrown. With an ATOMIC_MOVE you can move a file into a directory and be guaranteed that any process watching the directory accesses a complete file.
OCA Java 6, OCP Java 6, OCP Java 8
If the target of the path is a symbol link,
If the target of the path is a symbolic link,
OCA Java 6, OCP Java 6, OCP Java 8
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Jeanne Boyarsky wrote:I noted the move() thing privately. Scott and I had a lot of discussion about how to handle the options and this was the best we came up with. We will talk about it again with Java 9.
OCA Java 6, OCP Java 6, OCP Java 8
Don't get me started about those stupid light bulbs. |