java - How to save an ArrayList<String> to a txt file in Android Storage? -


i have arraylist one:

savedquestions = new arraylist<string>(); 

how save text file in android local storage when click button ?

even though arraylist class serializable default have make figur class (and classes uses) serializable well. mean like:

class figur implements serializable {     // handle version of class     private static final int serialversionuid = 1l;      // code go here } 

and have serialize like:

objectoutputstream fileout = new objectoutputstream(new fileoutputstream("file")); fileout.writeobject(list); fileout.close(); 

and deserialize:

objectinputstream filein = new objectinputstream(new fileinputstream("file")); list = (arraylist) filein.readobject(); filein.close(); 

also note, when write file, want append previous items in file , not overwrite (errase) them. think either objectoutputstream() or writeobject() has optional argument in allow append instead of overwrite. example: writeobject(list, true) instead of writeobject(list). you'll have research determine correct way it.

also, if cant serialization work, can instead store values "circle, rect, line, color, fill" makes 1 figur object in file single line delimiter such 'comma'' between them. read line file , use values make populated figur object. example: store these strings in file: 3,6,7,red,4 6,3,4,blue,8

then when read contents of file, build objects:

figur figure1 = new figur("3","6","7","red","4"); figur figure2 = new figur("6","3","4","blue","8");  arraylist<figur> figurs =new arraylist<figur>(); figurs.add(figure1); figurs.add(figure2); 

its not efficient using serialization, gets job done , contents of file in human readable form.

from link https://community.oracle.com/thread/1193052?start=0&tstart=0


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -