Writing to an existing file

  • 14
  • Locked
The main() method accepts three arguments: 1) fileName - the path to a file; 2) number - a position in the file; 3) text - the text. Write text to the fileName file starting at the position indicated by number. The write operation must overwrite the old data in the file.
You can't complete this task, because you're not signed in.
Comments (4)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Justin Smith
Level 39 , Greenfield, USA, United States
18 August 2022, 16:38
Interesting, my solution does something different from the CG solution, but it passed anyway. I had taken the conditions to require that if bytes would be written beyond the end of the file, then it must instead be written starting at the end position. However, the CG solution simply checks if the length of the text is greater than the length of the file, and if so, it writes starting at the file end. The difference between the two is that the text length could be much less than the file length, but number could be a position that would still go beyond the end of the file. In this case, the CG solution would not make any changes to the starting write position, but my solution would.
Ulan Mukanbetov
Level 26 , Bishkek, Kyrgyzstan
21 October 2019, 09:34
Sorry, I mixed-up tasks.
Ulan Mukanbetov
Level 26 , Bishkek, Kyrgyzstan
21 October 2019, 05:06
In requirements is written: Read text from the file, starting from the position indicated by number but validator takes in
read(byte[] b, int off, int len)
method only form zero position of a file. WTF? )
Level 41
21 October 2019, 06:04
I don't see this phrase in the requirements.