import java.net.URL; import java.io.IOException; import java.util.Scanner; public class Parser { public static void main (String args[]) { try{ URL reader = new URL("http://theochem.mercer.edu/csc204/data/gettysburg.txt");; Scanner in = new Scanner(reader.openStream()); int lineCount=0; while (in.hasNextLine()) { // The following line grabs the next line of text and trims it String line = in.nextLine().trim(); // This is where the magic happens. Try and trace it with a line of text. int index = line.indexOf(" "); // Find the location of the next space while ( index != -1 ) { // If the index is negative then no space was found String word = line.substring(0, line.indexOf(" ")); System.out.println(word); line = line.substring(line.indexOf(" ")+1, line.length()).trim(); index = line.indexOf(" "); } // Now process the last word on the line String word = line.substring(0,line.length()); System.out.println(word); index = 0; lineCount++; } } catch (IOException ex) { System.out.println("WEB URL NOT FOUND."); } } }