Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

6th Edition

1943153035, 978-1943153039

More Books

Students also viewed these Databases questions