CodeGym /Courses /Java Collections /Practice using File

Practice using File

Java Collections
Level 1 , Lesson 2
Available

"Hi, Amigo! I came up with a couple of interesting tasks for you."

"They can only be completed in IntelliJ IDEA. Take a look at these interesting conditions…"

28
Task
Java Collections, level 1, lesson 2
Locked
Iterating through a file tree
Iterating through a file tree
14
Task
Java Collections, level 1, lesson 2
Locked
Find all the files
Find all the files
28
Task
Java Collections, level 1, lesson 2
Locked
Advanced file search
Advanced file search
Comments (23)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Evgeniia Shabaeva Level 42, Budapest, Hungary
14 May 2025
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.
Hoist Level 38, San Diego, United States
2 June 2023
https://codegym.cc/help/14564
Hoist Level 38, San Diego, United States
2 June 2023
Closer. Detailed HELP discussion. https://codegym.cc/help/13767
Justin Smith Level 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!
Lisa L Level 47, Nuremberg, Germany
16 May 2022
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)
Hoist Level 38, San Diego, United States
11 June 2023
Level 47 --- unfair ; lol
Fadi Alsaidi Level 34, Carrollton, TX, USA
6 February 2022
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?
Gellert Varga Level 23, Szekesfehervar, Hungary
14 January 2022
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!:)
Lisa Level 41
17 November 2021
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.
Gellert Varga Level 23, Szekesfehervar, Hungary
3 January 2022
Thanks for the useful recommendation!
TheLordJackMC Level 39, Princeton, idk somewhere
6 August 2021
hey guys, im completeing every task in one or two attempts, but the average attempt score just keets changing randomly. is this a bug?
John Squirrels Level 2, San Francisco, Poland
7 August 2021
This average can be very different from one task to another. That's normal.
Jurij Thmsn Level 29, Flensburg, Germany
8 May 2021
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.