Java Project: Concepts Tested in this Program : Error Handling Text I/O Write a
ID: 3702514 • Letter: J
Question
Java Project:
Concepts Tested in this Program:
Error Handling
Text I/O
Write a program that reads lines from a file and prints them out, removing all occurrences of a specified string from the lines.
For example, if the class that housed your program was called RmvText, running this prompt on the command line:
java RmvText John filename
Would print out the contents of the file filename without any instances of the string John.
Your program should get the arguments from the command line.
Please include a screen snapshot of the output.
Must include flowchart, pseudocode, and UML diagram
Name your program’s file as RmvText.java
SAMPLE RUN #1: java RmvText going input
Explanation / Answer
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class RmvText { public static void main(String[] args) throws FileNotFoundException { Scanner fin = new Scanner(new File(args[1])); while (fin.hasNextLine()) { System.out.println(fin.nextLine().replaceAll(args[0], "")); } fin.close(); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.