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
Get step-by-step solutions from verified subject matter experts
