public class Fileservice { private Context context; public Fileservice(Context context){ this.context= context; } public void save(String filename,String filecontent) throws Exception{ FileOutputStream outstream = context.openFileOutput(filename, Context.MODE_PRIVATE); outstream.write(filecontent.getBytes()); outstream.close(); } }
String name = ed1.getText().toString(); String content = ed2.getText().toString(); Fileservice fileservice = new Fileservice(getApplicationContext()); try { fileservice.save(name, content); Toast.makeText(getApplicationContext(), "保存成功", 5000).show(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }