Home Tutorial Java Scjp Part10 SCJP Module-10 Question-5

 
 

SCJP Module-10 Question-5
Posted on: July 16, 2010 at 12:00 AM
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)

Related Tags for SCJP Module-10 Question-5:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.