Java: cod explain please. :) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Java: cod explain please. :)

1. FileOutputStream f1 = new FileOutputStream("fisier.txt") 2. for(byte b=10; b<50;b++) f1.write(b) 3. f1.close(); 4. RandomAccesFile f2 = new RandomAccesFile("fisier.txt","r") 5. f2.seek(10) 6. int i = f2.read(); 7. f2.close() 8. System.out.println("i = " + i) the result is 20 can somone say why?

22nd Jan 2017, 3:12 PM
Andrei Caran
Andrei Caran - avatar
1 Answer
+ 2
You should try and find a way to print the entire file to ensure what I'm about to say is accurate, but I think it's because of the line: f2.seek(10) this seeks out the tenth element appended to file, which is the number 20. This is because the computer creates an array for the file and adds an element each time you append to it. Hope this helps
22nd Jan 2017, 3:55 PM
Sean Kudebeh
Sean Kudebeh - avatar