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

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -