Java Splitting of strings from text File -
i'm trying split strings text file has tabs in between integers. integer /t integer /t integer.
50 1 2 46 1 15 38 1 16 43 1 21 4 1 25 24 1 35 2 1 43 6
i tried using string token arrayindexoutofboundsexception
came out, did debugging myself , found out this.
how codes like:
public static void main(string[] args) throws filenotfoundexception { scanner input = new scanner(new file("datas.txt")); string data; int = 0; while (input.hasnextline()) { data = input.nextline(); string[] sp = data.split("\\t+"); string n1 = sp[0]; system.out.println("|" + n1 + "|"); } input.close(); }
here's picture link of result when compile , run it.
edit: no idea why result turns out this. switched bufferedreader , everything's now. people.
change code follows
public static void main (string []args) throws filenotfoundexception { scanner input = new scanner(new file("d:\\sample.txt")); string data; int = 0; while(input.hasnextline()) { data = input.nextline(); string [] sp = data.split("\t"); string n1 = sp[0]; system.out.println("|" + n1 + "|" ); } input.close(); }
Comments
Post a Comment