Menu
Topics Index
...
`

Files-1896


If you need explanation Read this topic

If you need Answer Take test on this topic

Files-1896
What will be the output of the following program?
import java.io.*;
public class FileName {
    public static void main(String str[]) {
        try {
            FileWriter fw = new FileWriter("MCFile.txt");
            fw.write("red,blue,green,white,yellow,black");
            fw.close();
            InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File("MCFile.txt")));
            BufferedReader br = new BufferedReader(inputStreamReader);
            while (br.ready()) {
                System.out.println(br.readLine());
                br.close();
            }
        } catch (IOException e) {
            System.out.println("I/O exception is raised");
        }
    }
}

A. (EMPTY)
B. red
C. red,blue,green,white,yellow,black
D. Some other output
E. Compilation Error or Runtime Error
Topic: BufferedReader In Java

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.

C is ans.new file is created with name MCFILE in current directory and red,blue,grn white,yellow, black are stored in file. C is the answer.

Posted by Shabaaz Shaikz    2014-06-24 14:19:20


Ans is D..aftr printg all data in the file the exception is raised so the op is red blue,green,white,yello,black
I/O Exception is raised

Posted by Uday Kumar    2014-06-24 14:21:28


ans d...it prints option c and io exceptn  raised statemnt,bcz block statemnt needs finally keyword to avoi tis excptn

Posted by Maheshwari Natarajan    2014-06-24 14:22:15


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

Posted by Merit Campus    2014-06-25 04:06:31


© meritcampus 2019

All Rights Reserved.

Open In App