Question: / Java program to read a text file and display its contents on screen import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class ReadCourseFile { public
/ Java program to read a text file and display its contents on screen import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class ReadCourseFile { public static void main(String[] args) { // create a file object to point to text file "courses.txt" File file = new File("courses.txt"); try { // open the file Scanner scan = new Scanner(file); // if file has contents to read // loop to read the contents of the file while(scan.hasNext()) { // read and display the line read System.out.println(scan.nextLine()); } scan.close(); // close the Scanner object } catch (FileNotFoundException e) { // catch the exception if file not present System.out.println("File "+file.getName() +" not present "); System.exit(0); } } } // end of program to do this out put: Course Code = IT2249 | Credit hours = 6 | Course title = Introduction to Programing with Java Course Code = IT2230 | Credit hours = 3 | Course title = Introduction to Database Systems Course Code = IT4789 | Credit hours = 3 | Course title = Mobile Cloud Computing Application Development
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
