Context.MODE_WORLD_WRITEABLE -->allow all other applications to have write access to the created file.18 */19 flag=InsertInfo();20 if(flag){21 try{22 OutputStream outStream=FileStoreActivity.this.openFileOutput(file_name, MODE_PRIVATE);23 FileService.save(outStream, file_content);24 25 }catch(Exception e){26 Log.e(TAG, e.toString());27 resId=R.string.error;28 }29 Toast.makeText(FileStoreActivity.this, resId, Toast.LENGTH_LONG).show();30 }31 }32 33 34 });
2.读取文件的主要代码
读取主代码
1 Button bRead=(Button)findViewById(R.id.read); 2 bRead.setOnClickListener(new View.OnClickListener() { 3 4 @Override 5 public void onClick(View v) { 6 // TODO Auto-generated method stub 7 //此时隐藏了文件内容框和文件内容的label 8 filecontent.setVisibility(View.GONE); 9 TextView content=(TextView)findViewById(R.id.content);10 content.setVisibility(View.GONE);11 InputStream inStream;12 file_name=filename.getText().toString();13 14 /* API15 * FileInputStream openFileInput (String name) 16 * Open a private file associated with this Context's application package for reading. 17 */18 try {19 inStream = FileStoreActivity.this.openFileInput(file_name);20 String context=FileService.read(inStream).toString();21 Toast.makeText(FileStoreActivity.this, context, Toast.LENGTH_LONG).show();22 } catch (Exception e) {23 Log.e(TAG,e.toString());24 resId=R.string.error;25 }26 }27 });
3.关于编者的代码
关于编码代码
Button bAbout=(Button)findViewById(R.id.about); bAbout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub new AlertDialog.Builder(FileStoreActivity.this).setTitle("编者信息") .setMessage( "编者: naive_monk" + " " + "爱好:篮球、音乐、交友" + " " + "Q Q:1271522052" + " " + "邮箱:summerdir@gmail.com" + " " + "所在城市:广东惠州 " + " ") .setCancelable(false).setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(