import java.net.*; import java.io.*; /** ReadStudents.java reads lines from a file at a URL URL reading code Copied from: http://docs.oracle.com/javase/tutorial/networking/urls/readingURL.html on 01/17/2012. @version for CS56, W12 @author P.Conrad with help from oracle.com */ public class ReadStudents2 { public static final String studentsURL = "http://www.cs.ucsb.edu/~pconrad/cs56/12W/lect/01.17/students.dat"; public static void main(String[] args) throws Exception { URL cs = null; try { cs = new URL(studentsURL); } catch ( java.net.MalformedURLException mue ) { System.err.println("Oops " + mue); System.exit(1); } BufferedReader in = new BufferedReader( new InputStreamReader( cs.openStream())); String inputLine; while ((inputLine = in.readLine()) != null) { // split my inputLine at commas String [] result = inputLine.split(","); // Check that the result has two parts if (result.length != 2) { throw new Exception("Bad input line! " + inputLine); } // assign parts String name=result[0]; String perm=result[1]; // create new Student object // TODO @@@ Student s = new Student(name,perm); // TODO @@@ Add student into an array of students System.out.println("name = " + name + " perm=" + perm); } in.close(); } }