Android中以文件的形式保存数据

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();
                }

 

posted @ 2012-12-19 17:30  有梦想的小人物  阅读(199)  评论(0编辑  收藏  举报