fileinputstream - Android - read internal data -
i'm trying make app, , need save string, tinydb in appinventor. so, found there http://developer.android.com/guide/topics/data/data-storage.html#filesinternal i'm looking saving data internal storage, don't know how read it. say:
to read file internal storage:
call openfileinput() , pass name of file read. returns fileinputstream.
read bytes file read().
then close stream close()
but don't know how, code never works. googled how read internal storage, , no code worked. can please tell me, how read text internal storage? :)
this code:
edittext tagbox = (edittext)findviewbyid(r.id.edittext1); string tag = tagbox.tostring(); context context = getapplicationcontext(); fileinputstream fis = context.openfileinput( tag ); inputstreamreader in = new inputstreamreader(fis); bufferedreader br = new bufferedreader(in); string data = br.readline(); toast.maketext(getapplicationcontext(), data, toast.length_long).show();
ok, found solution. easiest way store data ,like tinydb in appinventor, using sharedpreferences:
sharedpreferences preferences = preferencemanager.getdefaultsharedpreferences(this); edtior editor = preferences.edit();
to store data:
editor.putstring("key", "value");
to read data:
string value = preferences.getstring("key");
file selectedfile = new file(path + "/" + selectedfromlist + ".txt"); fileinputstream fstream = null; arraylist sal = new arraylist(); try { fstream = new fileinputstream(selectedfile); bufferedreader br = new bufferedreader(new inputstreamreader(fstream)); string strline; //read file line line while ((strline = br.readline()) != null) { // print content on console sal.add(strline); } } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } //close input stream try { in.close(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); }
Comments
Post a Comment