java - How to read a file and scan it -
i have been trying code java script tries read file , displays array. scrip try , read array , fine last 1 of array , locks , can try , scan file using scan function let type down code , display line on.
this example:the dat file contains these:
bob smith dre 134
smith bre 331
we use scan find determine item in dat file. scan
dre 134
and displays
bob smith dre 134
so im trying array looks [bob, smith. dre, 134]
and we're trying find array[2] , array[3] via scan.
public static void main(string[] args) throws ioexception { // todo code application logic here // // read keywesttemp.txt // create token1 string token1 = ""; // for-each loop calculating heat index of may - october // create scanner infile1 scanner infile1 = new scanner(new file("d:/ltu work/eclipseworkspace/tst/src/stars1.dat")).usedelimiter(",\\s*"); // original answer used linkedlist, preferable use arraylist in cases // list<string> tempt = new linkedlist<string>(); list<string> temps = new arraylist<string>(); // while loop while (infile1.hasnext()) { // find next line token1 = infile1.next(); temps.add(token1); } infile1.close(); string[] tempsarray = temps.toarray(new string[0]); (string s : tempsarray) { scanner scan = new scanner(system.in); string pick = scan.nextline(); if (pick.equals(tempsarray[5])); { system.out.println("hello"); } }
thank assistant , sorry confusion
Comments
Post a Comment