Listing 12.16, ReplaceText.java, gives a program that replaces text in a source file and saves the change
Question:
Listing 12.16, ReplaceText.java, gives a program that replaces text in a source file and saves the change into a new file. Revise the program to save the change into the original file. For example, invoking java Exercise12_16 file oldString newString replaces oldString in the source file with newString.
Listing
Transcribed Image Text:
1 import java.jo.*: 2 import java.util.*; 3 4 public class ReplaceText { public static void main(String[] args) throws Exception { // Check command line parameter usage if (args.length != 4) { System.out.println( "Usage: java ReplaceText sourceFile targetFile oldStr newStr"); System.exit(1); 10 11 12 // Check if source file exists File sourceFile = new File(args[0]); if (!sourceFile.exists()) { System.out.println("Source file " + args[0] System.exit(2); 13 14 15 16 17 18 19 20 21 22 23 24 25 26 does not exist"); // Check if target file exists File targetFile = new File(args[1]); if (targetFile.exists()) { System.out.println("Target file " + args[1] + " already exists"); System.exit(3); 27 try ( // Create input and output files Scanner input = new Scanner(sourceFile); PrintWriter output 28 29 30 new PrintWriter(targetFile); %3D 31 while (input.hasNext ()) { String sl = input.nextline(); String s2 = sl.replaceAll(args [2], args[3]); output.println(s2); 32 33 34 35 36 37 38 39 } omm mmmmm
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 66% (6 reviews)
For executiong the program a sample file needs to be kept in the same directory where the java file ...View the full answer
Answered By
Saikumar Ramagiri
Financial accounting:- Journal and ledgers, preparation of trail balance and adjusted trail balance Preparation of income statement, retained earning statement and balance sheet Banks reconciliation statements Financial statement analysis Cash flow statement analysis (both direct and indirect methods) All methods of Depreciations Management Accounting:- Ratios Budgeting control Cash budget and production budget Working capital management Receivable management Costing:- Standard and variance costing Marginal costing and decision making Cost-volume-profit analysis Inventory management (LIFO, FIFO) Preparation and estimation of cost sheet Portfolio management:- Calculation of portfolio standard deviation or risk Calculation of portfolio expected returns CAPM, Beta Financial management:- Time value of money Capital budgeting Cost of capital Leverage analysis and capital structure policies Dividend policy Bond value calculations like YTM, current yield etc International finance:- Derivatives Futures and options Swaps and forwards Business problems Finance problems Education (mention all your degrees, year awarded, Institute/University, field(s) of major): Education Qualification Board/Institution/ University Month/Year of Passing % Secured OPTIONALS/ Major ICWAI(inter) ICWAI inter Pursuing Pursuing - M.com(Finance) Osmania University June 2007 65 Finance & Taxation M B A (Finance) Osmania University Dec 2004 66 Finance & Marketing. B.Com Osmania University June 2002 72 Income Tax, Cost & Mgt, Accountancy, Auditing. Intermediate (XII) Board of Intermediate May 1999 58 Mathematics, Accountancy, Economics. S S C (X) S S C Board. May 1997 74 Mathematics, Social Studies, Science. Tutoring experience: • 10 year experience in online trouble shooting problems related to finance/accountancy. • Since 6 Years working with solution inn as a tutor, I have solved thousands of questions, quick and accuracy Skills (optional): Technical Exposure: MS Office, SQL, Tally, Wings, Focus, Programming with C Financial : Portfolio/Financial Management, Ratio Analysis, Capital Budgeting Stock Valuation & Dividend Policy, Bond Valuations Individual Skills : Proactive Nature, Self Motivative, Clear thought process, Quick problem solving skills, flexible to complex situations. Achievements : 1. I have received an Award certificate from Local Area MLA for the cause of getting 100% marks in Accountancy during my Graduation. 2. I have received a GOLD MEDAL/Scholarship from Home Minister in my MBA for being the “Top Rank student “ of management institute. 3. I received numerous complements and extra pay from various students for trouble shooting their online problems. Other interests/Hobbies (optional): ? Web Surfing ? Sports ? Watching Comics, News channels ? Miniature Collection ? Exploring hidden facts ? Solving riddles and puzzles
4.80+
391+ Reviews
552+ 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
-
Write a program that replaces all occurrences of a word with a new word in all the files under a directory, recursively. Pass the parameters from the command line as follows: java Exercise18_31...
-
Revise Programming Exercise 2.8 to display the hour using a 12-hour clock. Here is a sample run: Listing 2.7, ShowCurrentTime.java, gives a program that displays the current time in GMT. Revise the...
-
Listing 8.3 gives a program that finds two points in a two-dimensional space nearest to each other. Revise the program so that it finds two points in a three-dimensional space nearest to each other....
-
Smart housing Inc. is negotiating a deal to build a house. The owner wants to start in early spring when the weather begins to moderate and build through the summer into the fall. The completion time...
-
Use Theorem 3 (but not Theorem 4) to show that if two rows of a square matrix A are equal, then det A = 0. The same is true for two columns. Why?
-
Sports Physical Therapy regularly uses hardware, software, and databases in a ___________ system and tests and develops applications in a ____________ system. a. Test, live b. Test, sandbox c....
-
Management is considering three alternatives to satisfy an urgent need. Each of the alternatives will completely satisfy the need, so no combinations have to be considered. The first costs, operating...
-
Northstar Company uses ABC to account for its chrome wheel manufacturing process. Company managers have identified four manufacturing activities that incur manufacturing overhead costs: materials...
-
Explain an existing healthcare initiative that address the disparities veterans face with access to mental health. Explain specific goals of the specific initiative to address the gap veterans face...
-
Susan finished work on system architecture issues, and her system design specification was approved. Now she is ready to address system implementation tasks, including quality assurance, structure...
-
Suppose you have Java source files under the directories chapter1, chapter2, . . . , chapter34. Write a program to insert the statement package chapteri; as the first line for each Java source file...
-
Write a program to create a file named Exercise12_15.txt if it does not exist. Write 100 integers created randomly into the file using text I/O. Integers are separated by spaces in the file. Read the...
-
Calculate the dipole moment of HF for the bonding MO in Equation (23.33). Use the method outlined in Section 23.8 to calculate the charge on each atom. The bond length in HF is 91.7 pm. The...
-
High Country Home Decor has three divisions: Traditional, Contemporary, and Rustic. High Country had sales of $7,100,000 during the most recent fiscal period. Fixed costs totaled $1,520,000. Sales...
-
The following questions (Q15-Q17) relate to Phill and Claire; clients who are interested in investing in real property. You are required to provide them with answers to the following questions. Phil...
-
A shipper decides to combine 3 LTL sized orders into a single truckload shipment using a carrier's stop-off in transit provision. If such a shipment is made from St. Louis, MO to the northern...
-
2. Following are the cash flows of projects A and N. Years Project A Project N 0 (45000) (35 000) 1 16000 0 2 16000 0 3 16000 4 16000 0 97000 a. Please calculate NPV, PI, IRR and MIRR. Cost of...
-
What is the number one most obvious reason why withdrawing money from an IRA before age 59 in order to make a charitable gift is NOT tax efficient?
-
On January 1, 2017, Eagle borrows $100,000 cash by signing a four-year, 7% installment note. The note requires four equal payments of $29,523, consisting of accrued interest and principal on December...
-
Recall that Chapter 8 described the binary search algorithm for finding a particular entry in an ordered list. The idea behind binary search is to begin looking in the exact center of the list. If...
-
An advantage of using the ArrayList class over the Arrays class is that an ArrayList _________________. a. Can hold more elements b. Is dynamically resizable c. Supports use with indexes d. Requires...
-
Write a program that creates two ArrayListsone to hold Strings and one to hold Integers. Prompt the user for a word, and while the user does not enter a sentinel value, continue to add each entered...
-
The List interface _________________. a. Allows items to be inserted after creation b. Cannot contain duplicate elements c. Does not allow items to be removed d. Cannot contain more than 100 elements
-
Natural Mosaic. Natural Mosaic Company (U.S.) is considering investing Rs54,000,000 in India to create a wholly owned tile manufacturing plant to export to the European market. After five years, the...
-
Base Electronics buys 2,000 shares of stock in Blue Mission Company for $20 per share on January 2 of the current year. Base Electronics does not have the ability to participate in the decisions of...
-
Chan and Fatina are forming a partnership. Chan is investing a building that has a market value of RM80,000. However, the building carries a RM56,000 mortgage that will be assumed by the partnership....
Study smarter with the SolutionInn App