Revise Programming Exercise 12.16 to replace a string in a file with a new string for all
Question:
Revise Programming Exercise 12.16 to replace a string in a file with a new string for all files in the specified directory using the command:java Exercise12_22 dir oldString newString
Listing
Transcribed Image Text:
import java.io.*; 2 import java.util.*; 4 public class ReplaceText { public static void main(String[] args) throws Exception { // Check command line parameter usage if (args.length != 4) { System.out.printın( "Usage: java ReplaceText sourceFile targetFile oldStr newStr"); System.exit(1); check command usage 8. 10 11 12 13 // Check if source file exists File sourceFile - new File(args[0]); if (!sourceFile.exists()) { System.out.println("Source file " + args[0] + " does not exist"); System.exit(2); 14 15 16 source file exists? 17 18 19 // Check if target file exists File targetFile = new File(args[1]); if (targetFile.exists()) { System.out.printIn("Target file " + args[1] + System.exit(3); 20 21 22 target file exists? already exists"); 23 24 25 26 27 try ( // Create input and output files Scanner input = new Scanner(sourceFile); PrintWriter output = new PrintWriter(targetFile); try-with-resources 28 29 create a Scanner create a PrintWriter 30 31 while (input.hasNext()) { String sl = input.nextline(); String s2 = s1.replaceAl1 (args [2], args[3]); output.println(s2); 32 has next? 33 read a line 34 35 36 37 38 39
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 66% (12 reviews)
Program plan Import the required packages into the program Create a class Exercise1422 to replace th...View the full answer
Answered By
Seema kuldeep
although I don't have an experience of teaching in a particular institute, previously I was an expert on Chegg and I have used to teach my batch mates and also my juniors.
5.00+
1+ Reviews
10+ Question Solved
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Question Posted:
Students also viewed these Computer science questions
-
Revise Programming Exercise 18.38 to move the tree to where the mouse is dragged. Write a program to display a recursive tree as shown in Figure 18.20. 1 Enter an order: Enter an order: Enter an...
-
Revise Programming Exercise 3.15 to add an additional $2,000 award if two digits from the user input are in the lottery number. Write a program that prompts the user to enter an integer for today?s...
-
Revise Programming Exercise 31.1 to write a server for multiple clients. Write a server for a client. The client sends loan information (annual interest rate, number of years, and loan amount) to the...
-
The given graph is a transformation of one of the six basic functions. Find an equation for the given graph. 10 'y -1 -2 -3 -5 -6 -7 -8 -9 -10 -15 -13 -9 -8 -7 -6 -5 4 3 -2 -1 0 1 2 3 45 -11
-
If det A is close to zero, is the matrix A nearly singular? Experiment with the nearly singular 4 ( 4 matrix A in Exercise 9 of Section 2.3. Compute the determinants of A, 10A, and 0.1A. In contrast,...
-
Profit-Volume Graph: Identification and Sensitivity Analysis (LO3) A typical profit-volume graph follows. Required a. Identify each of the following: 1. Area BDC 2, Area DEF 3. Point D 4. Line AC 5....
-
According to the pure expectations theory, what would happen if long-term rates were not an average of expected short-term rates? AppendixLO1
-
McCawl Company produces two products and uses a predetermined overhead rate to apply overhead. McCawl currently applies overhead using a plantwide rate based on direct labor hours. Consideration is...
-
6) A bank made a three-month Eurodollar loan and accepted a six-month Eurodollar deposit. The bank considers a 3 x 6 FRA for $10,000,000. The agreement rate is 6 percent. There are actually 90 days...
-
Write a switch statement to convert a letter grade into an equivalent numeric value on a fourpoint scale. Set the value of the variable gradeValue to 4.0 for an A, 3.0 for a B, 2.0 for a C, 1.0 for a...
-
Suppose that the text file on the Web http://cs.armstrong.edu/liang/data/Scores.txt contains an unspecified number of scores. Write a program that reads the scores from the file and displays their...
-
Suppose you have Java source files under the directories chapter1, chapter2, . . . , chapter34. Write a program to remove the statement package chapteri; in the first line for each Java source file...
-
At the end of 2022, Wasicsko AG has 180,000 of cumulative temporary differences that will result in reporting future taxable amounts as follows. 2023 .................... 70,000 2024...
-
What are the various protocols in telecom domain?
-
What are the various types of routing protocols?
-
For all the benefits they bring to business, social media and other communication technologies have created a major new challenge: responding to online rumors and attacks on a company's reputation....
-
Directions: Put your feet in the shoes of the business owner and suggest specific ways on how a business can gain profit and how it can be avoid loss Ways to Gain Profit 1. 2. 3. 4. 5. 1. 2. 3. 4. 5....
-
Define business intelligence Briefly discuss how your organisation can use business intelligence to improve decision-making Please see below rubric as guidance. Kindly list references in APA 7th...
-
Which of the following is false? a. The elements in an array are related in some way. b. All of the elements in an array have the same data type. c. All of the elements in a one-dimensional array...
-
How much more interest will be earned if $5000 is invested for 6 years at 7% compounded continuously, instead of at 7% compounded quarterly?
-
A generic method _________________. a. Resides in a generic class b. Cannot be overloaded c. Can contain only one parameter d. Uses at least one type parameter
-
A generic class is one that uses a(n) _________________. a. Overloaded method b. Generic method c. Type parameter d. Empty method
-
An object that can be used in a for each loop to process the elements in a Collection is a (n) _________________. a. Index b. Subscript c. Repeater d. Iterator
-
Ferris Ltd. is a Canadian controlled private corporation. For the year ending December 31, 2019, its accounting Net Income Before Taxes, as determined under generally accepted accounting principles,...
-
If Faten accomplishes her projects with high-quality results, but takes more time than other managers in the process, as a manager she is ______. Select one: a. effective, but inefficient b....
-
Moore Corporation repurchased 3,700 shares of its own stock for $60 per share. The stock has a par of $15 per share. A month later Moore resold 925 shares of the treasury stock for $68 per share....
Study smarter with the SolutionInn App