dimanche 7 décembre 2014

Can someone walk me through this java code?


Vote count:

0




I am having a difficult time comprehending how this java program works. I do know that we have the I/O library for the files. Here is the code: import java.io.*;



public class SimpleRandomAccessFile {
public static void main(String[] args) throws IOException {
RandomAccessFile inout = new RandomAccessFile("inout.dat", "rw");
inout.setLength(0);

for (int i = 0; i < 200; i++)
inout.writeInt(i);
System.out.println("Current file length is " + inout.length());
inout.seek(0);
System.out.println("The first number is " + inout.readInt());

inout.seek(2*4);
System.out.println("The third number is " + inout.readInt());

inout.seek(8*4);
System.out.println("The ninth number is " + inout.readInt());

inout.writeInt(200);

inout.seek(inout.length());
inout.writeInt(1000);
System.out.println("The new length is " + inout.length());

inout.seek(9 * 4);
System.out.println("The tenth number is " + inout.readInt());
inout.close();
}
}


Any help or feedback would be great! Thanks in advance!



asked 43 secs ago







Can someone walk me through this java code?

Aucun commentaire:

Enregistrer un commentaire