Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Exercise 1: Write a program that reads a text file, removes all occurrences of a specified String and stores the remaining words in another text
Exercise 1: Write a program that reads a text file, removes all occurrences of a specified String and stores the remaining words in another text file. You may assume that the text file contains Strings, one on each line.
*I am using JGrasp so please make sure it is compatible *Please comment throughout code *FULL QUESTION IN IMAGES BELOW
Exercise 0: Review the following three exercises that were discussed in the lectures. //A simple program that illustrates reading from a text file. It reads each line from the given text file and displays them on the screen import java.util. Scanner; import java.io. public class File ReadDemol public static void main (String[ args) throws IOException Scanner keyboard. Scanner System. in) new System out. print Enter the name of the file to read from String filename keyboard. nextLine File inFile new File (filename) Scanner input new Scanner (inFile); while (input.hasNext String line input. nextLine System.out.println (line) input close This program illustrates how to read from a URL /It opens the connection to the specified URL and reads each line and //displays it It also counts the total number of characters on the //webpage import java util Scanner import java.net. URL import java.io. public class ReadFileFromURL public static void main (String args) throws Exception Scanner keyboard new Scanner (System in) System. out.print Enter a URL String URLString keyboard. nextLine URL url new URL (URL string) int count Scanner input new Scanner (url openstream while input. hasNext ())f String line input. nextLine System.out.println (line); count+Jline length System. out.println ("The file size is count charactersStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started