In this Lab we will learn about reading and writing to files. We’ll also get some practice reading the java docs.

Then you will write a program to analyze a set of presidential speeches.

  • Note: If you aren’t able to click the links and see more content on this web page, try opening it in a different browser (e.g., Chrome).

Deadline: Wednesday 10/31

Please read this fully. You might learn something.

You can work individually, or with at most one other person.

First, get the files. Use this link to create one git repository per team. Once you’ve created the repository, go to its Settings Page on github and add your partner as a collaborator. This will allow both of you to push to the same repository.

IMPORTANT: Part of the goal of this lab is to get you more comfortable working with the official Java documentation. Therefore, the only websites you are allowed to visit while working on this are my website and websites that start with http://docs.oracle.com/. No googling stack overflow!

Opening Text Files to Read

First we will try to read from a file. You may have done this before, or you may know that a quick google search will give you code that you can copy and paste. Let’s pretend that’s not the case, and figure it out from scratch.

The most basic reference point for any Java question is the “Java Docs”. These give reasonably detailed explanations for every class and function in the entire Java library. Very handy. We will use the Java 6 docs since you are likely to have at least that version installed.

Open this in another window/tab: Java 6 API

We want to read from a file, which is a basic form of Input/Output, so we will have to find classes related to that. The top left of the window lists all of the packages in the core Java library. Find the java.io package. Clicking this changes the bottom left frame so that it becomes a list of all the classes in that particular package. Click the java.io link at the very top of the bottom left frame to see the package summary.

At the top of this view we get a list of the Interfaces supported by this package, followed by all of its classes. As you can see, there are a lot of classes related to working with files.

Read through the list of classes in java.io. If we want to write a program to read through a text file and print the lines in it to the screen, what classes do you think might be useful?

Record your answer in your README.md file, then click here.