Home » JAVA Programming » Serialization » Question
  1. What will be printed to the output and written to the file, in the below program?
    import java.io.*;  
    public class FileOutputStreamExample
    {
    public static void main(String args[])
    {
    try
    {
    FileOutputStream FOS = new FileOutputStream("D:\\InterviewMania.txt");
    String str="Welcome to the Interview Mania.";
    byte q[]=str.getBytes();//converting string into byte array
    FOS.write(q);
    FOS.close();
    System.out.println("Success");
    } catch(Exception e){System.out.println(e);}
    }
    }
    1. Only "Welcome to the Interview Mania"
    2. Compile time error
    3. "Success" to the output and "Welcome to the xInterview Mania"
    4. Runtime error
    5. None of these
Correct Option: C

First, it will print “Success” and besides that it will write “Welcome to the Interview Mania” to the file InterviewMania.txt.



Your comments will be displayed only after manual approval.