CodeGym /Courses /Java Collections /Tasks | Level 2 | Lesson 2 Tasks | Level 2 | Lesson 2 Java Collections Level 2, Lesson 2 Available "Hi, Amigo!" 14 Task Java Collections, level 2, lesson 2 Locked Writing to an existing file Writing to an existing file 14 Task Java Collections, level 2, lesson 2 Locked Using RandomAccessFile Using RandomAccessFile Comments (3) TO VIEW ALL COMMENTS OR TO MAKE A COMMENT, GO TO FULL VERSION Ruslan Skaldin Level 33, Tashkent, Uzbekistan 6 December 2020 Don't know why but when you compare two string it only accepts result with this construction: if (text.equals(new String(textInFile))) { ... } This one doesn't work: if (text.equals(Arrays.toString(textInFile))) { ... } Justin Smith Level 41, Greenfield, USA, United States 19 August 2022 I didn't even compare them in String form. What I used: if(Arrays.equals(readBytes, text.getBytes()) I was able to pass using this comparison. Ewerton Level 30, Belo Horizonte, Brasil 8 July 2019 Writing to existing file: "If the file is too short", means that number will be bigger than your file length. Using RandomAcessFile - helpful example: test.txt: Hi, good luck String[] args = {"C:\test.txt",4,"good"} Output: Hi, good lucktrue
GO TO FULL VERSION