i creating listview json data.when user offline want show data in listview. have stored json data in android sdcard. , retrive data when user offline , showed in listview. problem is, when read file directory it's show's me black diamond question mark , stores in array list. type of "����t��*" question how remove type of string arraylist. please help
save data:
public void savemydata() { try { objectoutput out = new objectoutputstream(new fileoutputstream(new file(getfilesdir(),"")+"cachefile.txt")); out.writeobject(al.tostring()); toast.maketext(getapplicationcontext(), "data saved..",toast.length_long).show(); out.close(); } catch (ioexception e) { e.printstacktrace(); } }
this retrieving code.
string filecontent = ""; try { string currentline; bufferedreader bufferedreader; fileinputstream fileinputstream = new fileinputstream(getfilesdir()+"cachefile.txt"); bufferedreader = new bufferedreader(new inputstreamreader(fileinputstream,"utf-8")); while ((currentline = bufferedreader.readline()) != null) { filecontent += currentline + '\n'; } bufferedreader.close(); } catch (ioexception e) { e.printstacktrace(); log.d("failed","thos null"); filecontent = null; } log.d("sucess","sucess buddyy"+filecontent);
broadly speaking, issue you're using objectoutputstream
write data file, bufferedreader
read in. objectoutputstream
designed allow objects , native data types written stream in way can read in via objectinputstream
reconstitute objects in same way. encoding not meant human readable , contains characters field separators.
i don't know al
is, since you're calling tostring()
before write it, can assume want actual strings in file can read. this, want use printstream
, printstream.println()
method instead of objectoutputstream
.
Comments
Post a Comment