Question: What is this code doing? What does it mean by reading from a file? Is it suppose to print something when it runs? I'm so

What is this code doing? What does it mean by "reading from a file"? Is it suppose to print something when it runs? I'm so confused. Can someone please explain.

import java.util.Scanner;

import java.io.File;

import java.io.PrintWriter;

import java.io.IOException;

public class readFile

{

public static void main(String[] args) throws IOException

{

if (args.length != 1)

{

System.out.println("usage: java readFile fileName");

System.exit(-1);

}

File fr = new File (args [0] );

if (!fr.exists())

{

System.out.println("Error: file " + args[0] + " not found. ");

System.exit(0);

}

Scanner infile = new Scanner(fr);

while (infile.hasNextLine())

{

String line = infile.nextLine();

System.out.println(line);

}

infile.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!