技术开发 频道

Android对文件的操作(简单文件读写)

  【IT168 技术】环境:1.系统:window7

  2.Android版本:2.2

  3.eclipse3.5.2(伽利略)

  一、基本的流程图(写入文件)

Android对文件的操作(上)

  二、模拟器运行界面

  1.主界面

Android对文件的操作(上)

  2.保存(不符合条件)

Android对文件的操作(上)

  3.正常保存

Android对文件的操作(上)

  4.读取文件

Android对文件的操作(上)

  5.关于编者

Android对文件的操作(上)

  三、代码如下:

  1.保存文件的主要代码

  保存的主代码

  1 bSave.setOnClickListener(new View.OnClickListener() { 2 3 @Override 4 public void onClick(View v) { 5 // TODO Auto-generated method stub 6 resId=R.string.success; 7 file_name=filename.getText().toString(); 8 file_content=filecontent.getText().toString(); 9 /* openFileOutput API10 * FileOutputStream openFileOutput (String name, int mode)11 * Open a private file associated with this Context's application package for writing. Creates the file if it doesn't already exist.12 */13 /* Context四种模式的API14 * Context.MODE_APPEND -->if the file already exists then write data to the end of the existing file instead of erasing it.15 * Context.MODE_PRIVATE -->the default mode, where the created file can only be accessed by the calling application (or all applications sharing the same user ID). 16 * Context.MODE_WORLD_READABLE -->allow all other applications to have read access to the created file.17 *

0
相关文章