Asked by Bailey Ennis on Jun 29, 2024

verifed

Verified

Write a complete Java program using a Scanner object that opens a file named autos.txt and displays each line to the screen.

Scanner Object

A class in Java used to parse primitive types and strings using regular expressions from an input stream.

Displays Line

A method or functionality used to output or print a line of text to a display screen or console.

  • Attain proficiency in creating Java statements and applications that execute fundamental file input/output tasks.
  • Cultivate proficiency in employing BufferedReader and Scanner objects to read data from text files.
verifed

Verified Answer

ZK
Zybrea KnightJul 05, 2024
Final Answer :
import java.util.*;
import java.io.FileReader;
import java.io.FileNotFoundException;
public class TextDemo
{
public static void mainString args[])
{
Scanner inputStream = null;
try
{
inputStream = new Scannernew FileReader"autos.txt"));
String line = inputStream.nextLine);
whileline != null)
{
System.out.printlnline);
line = inputStream.nextLine);
}
inputStream.close);
}
catchFileNotFoundException e)
{
System.out.println"Error opening files.");
}
}
}