java - Can we use PrintWriter Class for saving a string in a file in an Android App? If yes, then how? -
if can use printwriter class in making android app, mistake in following code? app stops working on pressing button 'save'
public void save(view view) { text=data.gettext().tostring(); printwriter writer=null; try { writer=new printwriter(filename); } catch (filenotfoundexception e) { msg.settext("filenotfoundexception"); } writer.print(text); writer.flush(); writer.close(); msg.settext("data saved successfully"); } }
this should trick. instead of creating file yourself, let android it.
text=data.gettext().tostring(); printwriter writer=null; try { fileoutputstream os = openfileoutput(filename, context.mode_private); writer=new printwriter(os); } catch (exception e) { // log exception } writer.print(text); writer.flush(); writer.close(); msg.settext("data saved successfully"); for more information on basic io operations, please have @ this: http://developer.android.com/training/basics/data-storage/files.html#writeinternalstorage
Comments
Post a Comment