Menu
Topics Index
...
`

Files1917


If you need explanation Read this topic

If you need Answer Take test on this topic

Files1917
What will be the output of the following program?
import java.io.*;

public class TextFile {
    public static void main(String str[]) {
        try {
            FileWriter fw = new FileWriter("filereadwrite.txt");
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write("have a good day");
            bw.close();
            FileReader fr = new FileReader("filereadwrite.txt");
            BufferedReader br = new BufferedReader(fr);
            br.read();
            br.read();
            br.skip(8);
            System.out.println((char) br.read());
            System.out.println(br.read());
            br.close();
        } catch (IOException e) {
            System.out.println("IOException : " + e.toString());
        }
    }
}

A. o
8
B. d
32
C. g
7
D. Some other output
E. Compilation Error or Runtime Error
Topic: Java BufferedWriter

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.

B
Given text is
"have a good day"
There are 2 read op, and then skip by 8 byte total 10 bytes
After that 11th char will be printed as it is type casted to char
And succeeding char is space whose equivalent decimal value is 32

Posted by Abhishek Kathuria    2014-05-06 12:59:39


answer is B because two br.read() and skip(8) returns the br to  the 11th character which is d and ascii code for space is 32 which is the next character.

Posted by Shiva Goud    2014-05-06 13:25:05


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

Posted by Merit Campus    2014-05-08 04:05:34


© meritcampus 2019

All Rights Reserved.

Open In App