Saving to File Android -
im having trouble debugging code of mine. simple note store app @ moment, attempts store string file in background. when run app on tablet toast confirms code ran, cant find file on tablets internal storage prove been stored?
my code:
public void onclick(view v) { //gets note detail fields. notecontent = content.gettext().tostring(); notetitle = title.gettext().tostring(); date date = new date(); if (notecontent.length() == 0 || notetitle.length() == 0) { toast.maketext(getapplicationcontext(), "please fill in both note title , content before saving", toast.length_long).show(); } else { //adds notes object of note. note creatednote = new note(notecontent, notetitle); //adds note object array. notearray.add(creatednote); //testing note test = notearray.get(0); string testtitle = test.gettitle(); string testcontent = test.getcontent(); system.out.println(testtitle); system.out.println(testcontent); //concatenating string. string notestring = testtitle + "-" + testcontent; try { fileoutputstream fo = openfileoutput(filename, mode_world_readable); outputstreamwriter osw = new outputstreamwriter(fo); try { system.out.println(notestring); osw.write(notestring); osw.flush(); osw.close(); toast.maketext(getbasecontext(), "note_saved", toast.length_long).show(); } catch(ioexception e) { e.printstacktrace(); } } catch (filenotfoundexception e) { e.printstacktrace(); }
i have included permissions read/write :s
<uses-permission android:name="android.permission.write_external_storage" /> <uses-permission android:name="android.permission.read_external_storage" />
using file explorer of ddms , browse /data/data/your_package/files/ <- can find file. refer here more options android: can not write txt file
Comments
Post a Comment