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");
(A)
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.