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% (9 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,...
-
The Sports Physical Therapy clinic is having trouble with the performance of their Access database. They would like to split the database between front end and back end to improve performance. How...
-
A university pumps its water from wells located on campus. The falling water table has caused pumping costs to increase, the quantity of water available to decrease, and the quality of water to...
-
Consider the bill of materials (BOM) in Figure. a. How many immediate parents tone level above) does Item 1 have? How many immediate parents does item E have? b. How many unique components does...
-
Create a table in excel showing net present value calculation for the following scenario. You will have a column with time period, future value, and present value included. You can anticipate that...
-
The number of students taking the Scholastic Aptitude Test (SAT) has risen to an all-time high of more than 1.5 million (College Board, August 26, 2008). Students are allowed to repeat the test in...
-
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...
-
A professor wonders if the number of hours students spend studying during the week before final exams is a function of their GPAs until that point. Ten students in four separate GPA brackets report...
-
5. Determine the capacitance required to establish a capacitive reactance that will match that of a 2 mH coil at a frequency of 50 kHz. 6. In Fig. 1, a. What is the sinusoidal expression for the...
-
Could you elaborate on the concept of "biofilm" and elucidate the mechanisms and environments conducive to its formation?
-
Public International Law and International Trade Compare and contrast the effects of multilateral trade arrangements (for example the World Trade Organisation/GATT) and regional trade organisations...
-
Using the information above, prepare abbreviated income statements for the years 2021 and 2022 using the cash basis of accounting. Sales $ Expenses Net Income/(Loss) +A $ Blue Spruce Corp. Income...
-
Complete the Instalment Activity Statement using the following information: An invoice totalling $5,505 did not have an ABN so the business withheld the mandatory amount from the payment to the...
-
On January 1, 2017, Brussels Enterprises issues bonds at par dated January 1, 2017, that have a $3,400,000 par value, mature in 4 years, and pay 9% interest semiannually on June 30 and December 31....
-
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
-
8. Use the figures given below to complete the Statement of Income for the Sunshine Restaurant (use the Excel worksheet provided separately and copy/paste your answer below. In the Assignment 1...
-
Can you explain key factors that will contribute to the success or failure of a business plan based on: product differentiation branding and marketing distribution and availability effective supply...
-
The idea that teens seem to share many similar behaviors is an example of: a. Generational microculture b. Age-based microculture c. Gender microculture d. Social class microculture
Study smarter with the SolutionInn App