java - When reading in file, and use nextLine() to move to the next line, it causes the read in to skip every other line -


try {         filereader in = new filereader("generibrand.txt");         input = new scanner(in).usedelimiter(":");     } catch (filenotfoundexception filenotfound) {         joptionpane.showmessagedialog(null, "no file found!");     }     try {         while (input.hasnextline()) {             string drugclass = input.next();             if (drugclass.equals("ab")) {                 meds = new antibiotic(input.next(), input.next(), input.next());                 medlist.add(meds);             } else if (drugclass.equals("av")) {                 system.out.println(drugclass);                 meds = new antiviral(input.next(), input.next(), input.next());                 medlist.add(meds);             } else if (drugclass.equals("ur")) {                 meds = new urinaryantiinfective(input.next(), input.next(), input.next());                 medlist.add(meds);             } else if (drugclass.equals("ps")) {                 meds = new parasympathomimetic(input.next(), input.next(), input.next());                 medlist.add(meds);             } else if (drugclass.equals("sa")) {                 meds = new sympathomimetic(input.next(), input.next(), input.next());                 medlist.add(meds);             } else if (drugclass.equals("no")) {                 meds = new opiate(input.next(), input.next(), input.next());                 medlist.add(meds);             } else if (drugclass.equals("ad")) {                 meds = new antidepressant(input.next(), input.next(), input.next());                 medlist.add(meds);             } else if (drugclass.equals("du")) {                 meds = new diuretic(input.next(), input.next(), input.next());                 medlist.add(meds);             } else if (drugclass.equals("db")) {                 meds = new diabetic(input.next(), input.next(), input.next());                 medlist.add(meds);             } else if (drugclass.equals("cs")) {                 meds = new cnsstimulant(input.next(), input.next(), input.next());                 medlist.add(meds);             } else if (drugclass.equals("cd")) {                 meds = new cardiac(input.next(), input.next(), input.next());                 system.out.println(meds.getbrandname() + ((cardiac) meds).getcategory());                 medlist.add(meds);             } else if (input.hasnextline()) {                 input.nextline();             }         }     } catch (exception ex) {         joptionpane.showmessagedialog(null, "something went wrong!");     } 

i have tried numerous tests see being displayed... confusing part me if stick in system.out.println(drugclass); @ beginning before if statements print out each of words line after line, , print of them. when take out print line, , refrain using input.nextline() move next line in text file, enters first if statement, , arraylist of meds not populated. when use input.nextline() in code skips every other line when iterating through file...

fairly confused how getting such odd results, have idea of why occuring? in advance!

i found issue, had not set delimeters in file, , noticed issue printing out each line , spotting out odd print outs , determined that, skipping line due delimeters. feel rather poorly explaining it. @ same time though having duplicate while(input.hasnextline()){if(input.hasnextline(){input.nextline()}}


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -