java.util.scanner - Reading in values from a tab delimited .txt file -
i attempting read in values tab delimited text file , store them arraylists. issue values such ethnicity , gang may contain multiple strings separated single space. there way make may read in strings until next tab? thank in advance.
while (file.hasnext()) // creates while loop using scanner, in // store values in arraylist until runs out // of values { // stores values tab delimited file in specified variable each // time while loop run serial = file.next(); last = file.next(); middle = file.next(); first = file.next(); soc = file.next(); birth = file.next(); ethnicity = file.next(); height = file.next(); weight = file.next(); gang = file.next(); reason = file.next(); datein = file.next(); dateout = file.next(); parole = file.next(); cell = file.next(); // stores values variables above in defined array list seriallist.add(i, serial); lastlist.add(i, last); middlelist.add(i, middle); firstlist.add(i, first); soclist.add(i, soc); birthlist.add(i, birth); ethnicitylist.add(i, ethnicity); heightlist.add(i, height); weightlist.add(i, weight); ganglist.add(i, gang); reasonlist.add(i, reason); dateinlist.add(i, datein); dateoutlist.add(i, dateout); parolelist.add(i, parole); celllist.add(i, cell); i++; // increases value each time loop runs }
assuming file line-separated. should read file line line.
fis = new fileinputstream("the_file_name"); br = new bufferedreader(new inputstreamreader(fis, charset.forname("utf-8"))); while ((line = br.readline()) != null) { values = line.split("\t"); serial = values[0]; last = values[1]; ... }
if want array of space-separated values, call values[6].split(" ");
Comments
Post a Comment