Menu
Topics Index
...
`

Files : Creating FileWriter FileReader and BufferedReader


If you need explanation Read this topic

If you need Answer Take test on this topic

Files : Creating FileWriter FileReader and BufferedReader
What will be the output of the following program?
import java.io.*;
public class GuessOutput {
    public static void main(String[] args) throws IOException {
        FileWriter fw = new FileWriter("file.txt");
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write("Hello, This is Merit Campus.");
        bw.close();
        FileReader fr = new FileReader("file.txt");
        BufferedReader br = new BufferedReader(fr);
        br.read();    
        br.skip(6);
        br.reset();
        System.out.println((char)br.read());
        br.close();
    }
}

A. T
B. r
C. C
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.

A is the correct answer as we are storing the string obj into file and while reading from the file first we are reading 1 character after that we are skipping 6 characters the the next charcter is T whic is printed

Posted by Ram Reddy Bitla    2013-08-23 12:36:21


ans is E...since we are not handling the exceptions that can be caused by the Filewriter or FileReader...

Posted by Santosh Munugota    2013-08-23 12:44:15


E or D is the option : Its gives some other o/p since we are resetting what ever is read i.e here the 6th character 'T' so it may give other o/p ! In few cases it may also throw an excptional error since IoException is not marked at br !

Posted by Shaik Nyamath    2013-08-23 13:29:17


ans is E.. runtime error as we have not marked any character in the stream of characters, the use of br.reset() gives runtime error

Posted by Pramod Jain    2013-08-23 18:03:08


Congratulations Santosh Munugota. You are this dose winner. Please send us your mobile details in a private message and we will process the recharge asap.

Posted by Merit Campus    2013-08-24 05:46:33


© meritcampus 2019

All Rights Reserved.

Open In App