SCJP Module-10 Question-7


 

SCJP Module-10 Question-7

The sample code given below will test your understanding of creating a file and writing data onto it by using the File and FileWriter respectively.

The sample code given below will test your understanding of creating a file and writing data onto it by using the File and FileWriter respectively.

Given a sample code:

import java.io.*;

class Test3 {
public static void main(String[] args) {
try {
File w = new File("test.txt");
FileWriter fw = new FileWriter(w);
fw.write("test message");
fw.close();
} catch (IOException e) {
System.out.println(e);
}}}

Is the above code can make a file and can write ? Choose correct option?

(A) Yes
(B) No

Answer:

(A)

Ads