What will be the output of the following Java program?
import java.io.FileOutputStream;
public class FileOutputStreamExample
{
public static void main(String args[])
{
try
{
FileOutputStream fout=new FileOutputStream("D:\\example.txt");
String s="Welcome to India.";
byte b[]=s.getBytes();//converting string into byte array
fout.write(b);
fout.close();
System.out.println("Success");
} catch(Exception e){System.out.println(e);}
}
}
import java.io.FileOutputStream;
public class FileOutputStreamExample
{
public static void main(String args[])
{
try
{
FileOutputStream fout=new FileOutputStream("D:\\example.txt");
String s="Welcome to India.";
byte b[]=s.getBytes();//converting string into byte array
fout.write(b);
fout.close();
System.out.println("Success");
} catch(Exception e){System.out.println(e);}
}
}A. "Success" to the output and "Welcome to India" to the file
B. only "Welcome to India" to the file
C. compile time error
D. No Output
Answer: Option A

Join The Discussion