After finally completing the last task, I want to point that there's an interesting idea behind this algorithm. It's that the match is supposed to be true not only when the passed search criterion meets the requirements, but also when it's not set (i.e. equals null, or 0). The match should only return false when the search criterion is set but doesn't meet the requirements. Then everything works.
Closer. Detailed HELP discussion.
https://codegym.cc/help/13767
Justin SmithLevel 41, Greenfield, USA, United States
30 July 2022
This is an interesting set of three tasks. Three different ways to get a file tree structure. They assume you'll use recursion for the first one, the second explicitly says not to use recursion (use a queue instead), and the third (and IMO superior) option is to use FileVisitor. Learned a lot here!
When creating the destiniation file, do not use the File constructor taking two arguments (new File(resultFileAbsolutePath, "allFilesContent.txt")). Validation will not accept it... lots of red until changed. You have to use new File(resultFileAbsolutePath.getParent() + "/allFilesContent.txt"); // getParentFile() instead of getParent() works as well
For the output... you have to create an output stream the usual way. Files.newOutputStream(dest) is not accepted. But you can use Files.copy(path, outStream); to copy the content of each file (just don't forget to add the \n)
I don't get this approach of CodeGYM sometimes??!!! either directly say read about a certain API ,like they used to do in the past, or flat out say don't' use such and such technics, like don't use recursion to travers through the subdirectories. Also, Anyone here can give us an advice on how to find a good API to resolve an issue besides asking in stackoverflow?
Task-3101:
1) The file "/allFilesContent.txt" must be on the same path as args[1].
2) File renaming is a critical operation. First check if "/allFilesContent.txt" already exists on disk, and if so delete it, and only then rename the first file.
3) It is mandatory to use the methods in the FileUtils CG class.
4) This rename operation should be at the very beginning of the program, do nothing else before.
5.) All subfolders of args[0] and all their subfolders must be explored, no matter how deep the directory structure.
6) Do not use PrintStream to write to the target file, they will not accept it. CG will only accept FileOutputStream.
7) It is safer to put the entire write operation in a try-catch block.
8) write "\n" == write(10) . (The ASCII code of the line-feed is 10.)
Unfortunately I had 19 attempts; I wish you have less!:)
Java IO NIO and NIO.2 (Jeff Friesen), chapter 12: Improved File System Interface
Everything explained here in detail. Recommended reading for these and the following few tasks.
Iterating through a file tree:
make sure to to
first rename the file
second sorting(etc.)
If you do it in the order as requested in the Conditions, Validation will fail.
GO TO FULL VERSION