In this lesson we are going to take advantage of the fact that the scanner object is an iterator to process input from a source. We have a file in .inp format that contains a list of URLs for the program to dissect. The example program uses two scanners located within a nested while loop to read the information. The first loop reads each line of the file or each URL, and the second part uses a delimiter “/” to print each part of the URL.
If there is an issue opening the file or finding the file the program will throw an IO Exception. This is written into the code by putting the phrase “throws IOException directly after calling the main method.
public static void main(String[] args) throws IOException {
//write code here
}
Questions
- Why did 2 different scanners have to be used?
Words to know
- iterator: an object that allows you to process a collection of items one at a time.
- Uniform Resource Locators : The long name of URLs or web addresses
- delimiter: The character used to detect how to break up a string or break up tokens using the scanner object. Ex.- to break up parts of a URL the example program used /