Menu
Topics Index
...
`

Random Access file2941


If you need explanation Read this topic

If you need Answer Take test on this topic

Random Access file2941
What will be the output of the following program?
import java.io.*;
public class ExampleRandomAccessfile {
    public static void main(String[] args) throws IOException {
        File file = File.createTempFile("Alphabets", "txt");
        RandomAccessFile raf = new RandomAccessFile(file, "rw");
        raf.write("ABCDE\nFGHIJK".getBytes());
        System.out.print(raf.readLine() + "~");
        raf.seek(1);
        System.out.print(raf.readLine() + "~");
        raf.write("12345\n6789".getBytes());
        raf.seek(3);
        System.out.print(raf.readLine());
        raf.close();
    }
}

A. null~BCDE~DE
B. ABCDE~BCDE~DE
C. ABCDE~BCDE~45
D. null~BCDE~45
E. Compilation Error or Runtime Error
Topic: Java RandomAccessFile

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ans c
readlin return abcde in 1st sop
2nd seek 1 so bcde printd
previous lines ovrride with 12345 nums
aft seek 3 it prints 45

Posted by Maheshwari Natarajan    2014-08-25 08:50:14


answr b.
1st sop prints abcde
2 nd bcde
3rd de
bcz numbrs are append with previous char

Posted by NagaRaj Nataraj    2014-08-25 08:53:33


answer a.
initially seeks in end position so readline returns null
nxt seek set to 1 it print bcde upto end of line
thn seek 3 sop prints de

Posted by Anand Kumar    2014-08-25 13:33:27


Congratulations Anand Kumar. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-08-26 05:00:05


© meritcampus 2019

All Rights Reserved.

Open In App