android - Read Text file and fill the data in Array. -
im pretty sure im asking silly question but, jut in have txt file has data on it
unipub;112 binara st;act
mooseheads;54 cohen st;act
cube;24 mawson st;act
ill read in application using code:
package au.edu.canberra.g30813706; import java.io.bufferedreader; import java.io.file; import java.io.fileinputstream; import java.io.filenotfoundexception; import java.io.ioexception; import java.io.inputstreamreader; import java.util.arraylist; import java.util.arrays; import android.app.activity; import android.os.environment; public class filereader extends activity{{ arraylist<string> sinfo = new arraylist<string>(); string txtname = "accomodationtxt.txt"; file root = environment.getexternalstoragedirectory(); file path = new file(root, "canberratourism/" + txtname); try { bufferedreader br = new bufferedreader ( new inputstreamreader( new fileinputstream(path))); string line; string[] salineelements; while ((line = br.readline()) != null) { //the information split segments , stored array salineelements = line.split(";"); (int = 0; < salineelements.length; i++) sinfo.add(salineelements[i]); //sinfo.addall(arrays.aslist(salineelements[0], salineelements[1], salineelements[3])); } br.close(); } catch (filenotfoundexception e) { system.err.println("filenotfoundexception: " + e.getmessage()); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); }} }
how differentiate lines in array?
for example
i want display text of names on 1 page,
unipub
mooseheads
cube
what adding string arrays arraylist instead of individual elements.
this:
arraylist<string[]> sinfo = new arraylist<string[]>(); string line; string[] salineelements; while ((line = br.readline()) != null) { //the information split segments , stored array salineelements = line.split(";"); sinfo.add(salineelements); }
then loop through sinfo , use first element in each array in sinfo.
Comments
Post a Comment