Question 12
Consider the code given below.
Assume that file "data.txt" exists and contains the following text.
I love my country
Assume that there is no file named "newdata.txt".
import java.io.*;import java.util.Scanner;public class FileTest { public static void main(String[] args) throws Exception{ try { FileInputStream in = new FileInputStream("data.txt"); Scanner sc = new Scanner(in); String data = ""; if(sc.hasNext()) data = sc.nextLine();
var out = new FileOutputStream("newdata.txt", false); var dout = new DataOutputStream(out); dout.writeBytes(data); System.out.println("Data written to newdata.txt successfully"); out.close(); dout.close(); sc.close(); } catch (FileNotFoundException e) { System.out.println("File not found....."); } catch (IOException e) { System.out.println("Sorry there is an IO Error"); } }}Choose the correct option regarding the code.