Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Author: Olena Ratelle
- //Assignment: 05_Strings
- //Due Date: 03/14/2018
- //Date: 03/11/2018
- //Course: CIS 016-31478
- package Chapter5;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- public class StringBuilderClass_06 {
- public static void main(String[] args) {
- try {
- File fileToBeModified = new File("/Users/olenaratelle/Documents/pcc/cis016/hw/StringBuilderClassAssignment.txt");
- //Using BufferedReader read text from the file
- BufferedReader reader = new BufferedReader(new FileReader(fileToBeModified));
- String line = "", oldtext = "";
- while((line = reader.readLine()) != null)
- {
- oldtext += line + "\r\n";
- }
- reader.close();
- //Replace words "it" and "It" in a file
- String newText = oldtext.replaceAll("it", "Elena").replaceAll("It", "Elena").replaceAll(",", ":");
- //Print the result
- System.out.println(newText);
- //Save result to the newFile.txt
- FileWriter writer = new FileWriter("/Users/olenaratelle/Documents/pcc/cis016/hw/newFile.txt");
- writer.write(newText);
- writer.close();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- }
Add Comment
Please, Sign In to add comment