137k views
0 votes
Insert the missing code in the following code fragment. This fragment is intended to read a file named data In.txt and write to a file named dataOut.txt public static void main(String[] args) throws FileNotFoundException { String inputFileName = "dataIn.txt"; String outputFileName = "dataOut.txt"; File inputFile = new File(inputFileName); Scanner in = a. new Scanner(inputFile); PrintWriter out = } b. new Scanner(outputFile) c. new PrintWriter(outputFileName) d. new Print Writer(outputFile) e. new Scanner(outputFileName)

1 Answer

6 votes

Answer:

The missing code to create a PrintWriter object for the output file is:

c. new PrintWriter(outputFileName)

So the complete code fragment would be:

public static void main(String[] args) throws FileNotFoundException {

String inputFileName = "dataIn.txt";

String outputFileName = "dataOut.txt";

File inputFile = new File(inputFileName);

Scanner in = new Scanner(inputFile);

PrintWriter out = new PrintWriter(outputFileName);

// Rest of the code goes here

}

Step-by-step explanation:

User Eric Cote
by
7.4k points