File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RAF question from javacaps mock, help requested

 
sarim raza
Ranch Hand
Posts: 232
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
60. What is the output displayed by the following code?
import java.io.*;
public class TestIPApp {
public static void main(String args[]) {
RandomAccessFile file = new RandomAccessFile("test.txt", "rw");
file.writeBoolean(true);
file.writeInt(123456);
file.writeInt(7890);
file.writeLong(1000000);
file.writeInt(777);
file.writeFloat(.0001f);
file.seek(5);
System.out.println(file.readInt());
file.close();
}
}
Select correct answer:
A) 123456
B) 7890
C) 1000000
D) .0001

THE CORRECT ANSWER IS B, HOWEVER I THOUGHT THAT SEEK(5) WOULD START INDEXING FROM 0 AND WOULD STOP AT THE FLOAT VALUE OF .0001.
PLEASE CLEAR MY CONCEPTIONS OF THIS SEEK METHOD, THANKS !
 
ravi chan
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sarim,
boolean takes 1 byte, int takes 4 and long takes 8 bytes.
so file.seek(5) is at the 5th byte in the file which is nothing but 7890.
the file looks like this
true 123456 7890 1000000 and so on
1byte]4byte]4byte]------
1 + 4 ] 5th byte starts right at 7 and the whole int is printed - 7890
 
sarim raza
Ranch Hand
Posts: 232
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THANKS A LOT RAVI, THAT WAS GREAT !!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic