Question: Modify the processFile method so that it will compile and it will not produce a runtime error: public static void processFile(File file) { File input

Modify the processFile method so that it will compile and it will not produce a runtime error:

public static void processFile(File file) { File input = "contents.txt"; String line = null; try { input = new File(file); while ((line = input.readLine()) != null) { System.out.println(line); } return; } finally { if (file != null) { file.close(); } } } This is what I have so far, but I am stumped: 

import java.io.File;

import java.io.FileNotFoundException;

public class shortanswer

{

public static void processFile(File file) throws FileNotFoundException

{

File input = new File("contents.txt");

String line = null;

try

{

input = new File(line);

while ((line = input.readLine()) != null)

{

System.out.println(line);

}

return;

}

catch(FileNotFoundException exception)

{

System.out.println("File not found");

}

finally

{

if (file != null)

{

file.close();

}

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!