Menu
Question Index
...

What will be output of the following program? Assume that directory structure is already created.

import java.io.*;
public class OutputStreamDemo {
    public static void main(String[] args) throws IOException {
        File f = new File("D:\\Programs\\College.java");
        OutputStream os = new FileOutputStream(f);
        if (f.exists()) {
            System.out.println("File exists.");
            byte b[] = {'M', 'E', 'R', 'I', 'T', ' ', 'C', 'A', 'M', 'P', 'U', 'S'};
            os.write(b);
        } else
            System.out.println("File not found.");
        os.close();
        InputStream is = new FileInputStream(f);
        int i = 0;
        while ((i = is.read()) != -1) {
            System.out.print((char) i);
        }
        is.close();
    }
}


File exists.
MERIT CAMPUS
File not found.
File exists.
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java FileOutputStream

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App