java - How to filter out info by using useDelimiter -


so, trying info text file,

      example, 134567h;gabriel;24/12/1994;67;78;89 

then display only admin number first 1 not whole line in drop down list. here codes :

    public static string[] readfile(){     string file = "output.txt";     arraylist <string> studentlist = new arraylist <string> ();     try{     filereader fr = new filereader(file);     scanner sc = new scanner(fr);     sc.usedelimiter(";");      while(sc.hasnextline()){         studentlist.add(sc.nextline());     }      fr.close();     }catch(filenotfoundexception exception){         system.out.println("file " + file + " not found");     }catch(ioexception exception){         system.out.println(exception);     }     return studentlist.toarray(new string[studentlist.size()]); } 

and how populate drop down list :

    public void populate() {     string [] studentlist ;     studentlist = question3readfile.readfile();      jcombobox_adminno.removeallitems();      (string str : studentlist) {        jcombobox_adminno.additem(str);     } } 

however, problem options in drop down list showing whole line text file. not showing admin number only. tried usedelimiter already. supposed use that?

any appreciated. in advance.

rince check.

    public class question3readfile extends question3 {  private string adminno;  public question3readfile(string data) {     string[] tokens = data.split(";");     this.adminno = tokens[0]; }  public static string[] readfile(){     string file = "output.txt";     arraylist <string> studentlist = new arraylist <string> ();     try{     filereader fr = new filereader(file);     scanner sc = new scanner(fr);      while(sc.hasnextline()){         studentlist.add(new question3readfile(sc.nextline()));     }      fr.close();     }catch(filenotfoundexception exception){         system.out.println("file " + file + " not found");     }catch(ioexception exception){         system.out.println(exception);     }     return studentlist.toarray(new string[studentlist.size()]); } 

hasnext , next instead of hasnextline , nextline

public static void main(string[] args) {      string input = " example, 134567h;gabriel;24/12/1994;67;78;89";      scanner scanner = new scanner(input);      scanner.usedelimiter(";");      string firstpart = null;      while(scanner.hasnext()){          firstpart = scanner.next();          break;      }       string secondpart = input.split(firstpart)[1].substring(1);      system.out.println(firstpart);      system.out.println(secondpart);      scanner.close(); } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -