SCJP Module-10 Question-5


 

SCJP Module-10 Question-5

This sample code will test your understanding of opening a file and writing data onto the file.

This sample code will test your understanding of opening a file and writing data onto the file.

Given a sample code:

1    import java.io.*;

2    class Test3 {
3    public static void main(String[] args) {
4    try {
5    // Place code here.
6    w.write("hello user");
7    w.close();
8    } catch (IOException e) {
9    System.out.println(e);
}}}

What code can be placed at line no 5 for creating a file and writing to it ? Choose the correct options?

(A) FileWriter w = new FileWriter("user.txt");
(B) File w = new File("user.txt");

Answer:

(A)

Ads