i need some help with trying to read in a text file. the directions are:
A line that starts with # is a comment line. Comment lines and empty lines should be ignored.
Each course occupies one line. Each course has three fields: course code, course title, and prerequisites. Fields are separated by comma, and prerequisites are separated by white space(s). Note that some courses like CS120 do not have prerequisites.
i cant get it to work at all , for some reason the splits dont work and i dont know how to make it read in 3 fields. This is the final part of my project thats due in 2 hours and ive been at trying to get it to work since last night . im stumped, ive done simple readin files but none this complicated.
List<Courses> entries = new ArrayList<Courses>(); BufferedReader br = null; try { String string; String[] array; br = new BufferedReader( new FileReader( getServletContext().getRealPath("/WEB-INF/undergrad_courses.txt"))); while ((string = br.readLine()) != null) { if(string.startsWith("#")) { continue; } string.split(",").toString(); string.split(" "); entries.add(string"); System.out.println(string); } } catch (IOException e) { e.printStackTrace(); } finally { try { if (br != null) br.close(); } catch (IOException ex) { ex.printStackTrace(); } }