android separating a text file -
i've been researching how diablo 2 dynamically generates loot, , thought it'd fun create fun app randomly generate items using system.
i have code believe should read entire txt file, it's not parsed.
it looks like:
private void itemgenerator() {         int ch;         stringbuffer strcontent = new stringbuffer("");         inputstream fs = getresources().openrawresource(r.raw.treasureclass);         // read file until end , put strcontent         try {             while((ch = fs.read()) != -1){                 strcontent.append((char)ch);             }         } catch (ioexception e) {             // todo auto-generated catch block             e.printstacktrace();         } } an example in text file like:
treasure class  item1   item2   item3 tc:armo3    quilted_armor   buckler leather_armor tc:armo60a  embossed_plate  sun_spirit  fury_visor tc:armo60b  sacred_rondache mage_plate  diadem so i'm thinking right putting each row array stringtokenizer delimited \n each row.  somehow again tab-delimited each item in array , put 2d array?
i haven't coded yet because think there's better way implement haven't been able find, , hoping helpful input on matter.
for interested in knowing how item generation works, wiki page, http://diablo2.diablowiki.net/item_generation_tutorial, goes in-depth!
i think facing problem in distinguishing between each lines read-out file. in order read file line-by-line should change code below:
inputstream fs = getresources().openrawresource(r.raw.treasureclass); bufferedreader br = new bufferedreader(new inputstreamreader(fs)); string line = null; while((line = br.readline()) != null){     log.i("line", line);     //split content of 'line' , save them in desired way } 
Comments
Post a Comment