Guest User

Untitled

a guest
Mar 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. //Author: Olena Ratelle
  2. //Assignment: 05_Strings
  3. //Due Date: 03/14/2018
  4. //Date: 03/11/2018
  5. //Course: CIS 016-31478
  6.  
  7.  
  8. package Chapter5;
  9. import java.io.BufferedReader;
  10. import java.io.File;
  11. import java.io.FileReader;
  12. import java.io.FileWriter;
  13. import java.io.IOException;
  14.  
  15.  
  16.  
  17. public class StringBuilderClass_06 {
  18. public static void main(String[] args) {
  19. try {
  20. File fileToBeModified = new File("/Users/olenaratelle/Documents/pcc/cis016/hw/StringBuilderClassAssignment.txt");
  21. //Using BufferedReader read text from the file
  22. BufferedReader reader = new BufferedReader(new FileReader(fileToBeModified));
  23.  
  24. String line = "", oldtext = "";
  25. while((line = reader.readLine()) != null)
  26. {
  27. oldtext += line + "\r\n";
  28. }
  29. reader.close();
  30. //Replace words "it" and "It" in a file
  31. String newText = oldtext.replaceAll("it", "Elena").replaceAll("It", "Elena").replaceAll(",", ":");
  32. //Print the result
  33. System.out.println(newText);
  34. //Save result to the newFile.txt
  35. FileWriter writer = new FileWriter("/Users/olenaratelle/Documents/pcc/cis016/hw/newFile.txt");
  36. writer.write(newText);
  37. writer.close();
  38.  
  39. }
  40.  
  41.  
  42. catch (IOException e)
  43. {
  44. e.printStackTrace();
  45. }
  46. }
  47. }
Add Comment
Please, Sign In to add comment