In the first section of this assignment, you will write methods to perform basic text analysis on a document.
Here is a text file with a portion of President Barack Obama's acceptance speech. You can test your programs using this text file. PoliticalSpeech.txt
Here is the code that you can use to read in a text file from your computer. You will need to add the path in the appropriate place to identify where the text file is saved on your own computer.
You may not use any of the built-in Java methods or libraries that many entirely solve any of the above problems. You can use built-in methods such as "length()" for finding the length of a string.
TextFileReader:
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class Test {
public static void main(String [] args) {
String fileName = "*****************INSERT PATH HERE********************";
String line = null;
try {
FileReader fileReader =
new FileReader(fileName);
BufferedReader bufferedReader =
new BufferedReader(fileReader);
while((line = bufferedReader.readLine()) != null) {
System.out.println(line);
}
bufferedReader.close();
}
catch(FileNotFoundException ex) {
System.out.println(
"Unable to open file '" +
fileName + "'");
}
catch(IOException ex) {
System.out.println(
"Error reading file '"
+ fileName + "'");
}
}
}