Menu
Question Index
...

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();
    }
}


null~BCDE~DE
ABCDE~BCDE~DE
ABCDE~BCDE~45
null~BCDE~45
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java RandomAccessFile

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App