Sequential file output

  • 18
  • Locked
1. Figure out what the program does. 2. In a static block, read 2 filenames: firstFileName and secondFileName. 3. Inside the Solution class, create a public static ReadFileThread class that implements the ReadFileInterface interface (Think about what is more appropriate: Thread or Runnable). 3.1. Th
You can't complete this task, because you're not signed in.
Comments (9)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Олег Байбула
Level 27 , Ukraine
Expert
26 January, 15:40
I like that this task also works with Stream, Files and Scanner classes instead of declared imports.
Mary Khan
Level 23 , Russia, Russian Federation
22 November 2022, 22:02
Can anyone explain the difference between extending Thread and implementing Runnable? Which one to use in which case? In this task, I implemented Runnable instead of extending Thread and run() simply didn't work for me.
Justin Smith
Level 37 , Greenfield, USA, United States
17 September 2021, 02:42
This task has really confusing conditions. For the longest time I didn't understand the difference between conditions 3.2 and 3.3. I did all the work inside getFileContents and had nothing left to put in run(). I want to help anyone else who might be confused by this with a simple hint: Think of getFileContents as a getter method for the string that you build in the run() method. The run() method does the work of getting the data from the file and constructing the string line by line. The getFileContents just returns the string or an empty string if it's null. It doesn't do any work other than that.
Aakankasha Sharma
Level 18 , Chandigarh, India
16 April 2021, 19:25
7 attempts, and I will never forget that I have to check IOException for a bufferedReader ;p
4 February 2021, 13:02
Another misleading task. I just wasted an hour trying to retrieve File Path based on File Name in my run method. firstFileName and secondFileName should say retrieve file name with the file path (e.g. "D:/one.txt" instead of "one.txt").
Agent Smith
Level 38
31 August 2020, 20:28
If you are stuck on a getFileName() returning an empty string or giving you a null pointer exception - just carefully think what happens first: 1) System.out.println(f.getFileContents()) being called or 2) f.start() getting finished? ;-)
Petros
Level 23 , Columbia, United States
14 August 2020, 21:22
The getFileName() method had be stuck. It just acts as a getter apparently (duh lol) but I was stuck on it for a while. You just have to return what the run method was supposed to do, otherwise return an empty string.
Ewerton Backend Developer
2 July 2019, 18:51
If you are stuck on the "The ReadFileThread class's run method should read lines from the file set by the setFileName method. And the getFileContents method of this same class must return the file contents. The return value is one string consisting of the lines of the file, separated by spaces." 1) Don't throw any exceptions; 2) Set your content string to "" before run.
Henrique
Level 41 , São Paulo, Brazil
11 June 2020, 19:30
I'm stuck exactly on this part. And I'm so stuck that I cannot even understand your hint :'(