Review:
CSE148 Object Oriented Programming Homework Set 08
1. Exception and Exception handling
a. Checked and unchecked exceptions
b. Catch exception; declare, throw exception
2. Text file I/O, and classes File, Scanner, PrintWriter
Write a Java program to:
1. Implement a method ¡°int countFiles(String path)¡±. The parameter is the path to a folder. The method will list all files in this folder and its subfolders. Return the total number of the files.
(Clue: (1) File class has these methods defined: listFiles(), isFile()/isDirectory(); (2) Use ¡°ArrayList¡± to implement Stack or Queue operation)
2. Implement a method to replace a word in a text file, save result in a new file:
int findAndReplace(String file, String originalWord, String newWord);
Parameter ¡°file¡± is the name of original text file to be read; originalWord is the word to be found and replaced in the file, newWord is the word to replace orignalWord. The method will also count how many words have been found and replaced. Return this number.
SCCC CSE148, Spring 2021