将用户输入的文本保存到android文件系统中。文件被保存在android文件系统的/data/data/your.packet.name.appname/files/folder, 查看这个文件可以通过在eclipse -> Windows -> Open Perspective > Other -> DDMS-> File Explore -> data -> data ...-> samplefile.txt 选中后 点击右上脚 “Pull a file from device”

1. SaveFile.java

public class ReadFile extends Activity implements View.OnClickListener { private static final String TAG = "ReadFileActivity"; /** Called when the activity is first created. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); Button readButton = (Button) findViewById(R.id.button1); readButton.setOnClickListener(this); Button clearButton = (Button) findViewById(R.id.clearbutton); clearButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { TextView textArea = (TextView) findViewById(R.id.filecontent); textArea.setText(""); } }); } public void onClick(View arg0) { doReadFromFile(this); } private void doReadFromFile(Context context) { InputStream istream = null; BufferedReader br = null; String fileContent = "", line=""; try { istream = (InputStream) context.getResources().openRawResource(R.raw.mytext); br = new BufferedReader(new InputStreamReader(istream)); while ( (line = br.readLine()) != null) { fileContent += line + "/n"; } br.close(); istream.close(); } catch (Exception e){ Log.e(TAG, "Found exception when reading file: " + e); } Log.i(TAG, "file content = " + fileContent ); TextView showContent = (TextView) findViewById(R.id.filecontent); showContent.setText(fileContent); } }

更多相关文章

  1. NPM 和webpack 的基础使用
  2. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
  3. 手把手搭建 android 开发环境||资源打包下载【更新到android 4.2
  4. android一些基础知识
  5. android编译过程详解(二)
  6. ANDROID问题总结
  7. 【Android开发学习06】Android中的文件I/O操作
  8. Android实例剖析笔记(二)
  9. Android(安卓)Studio连接STF失效

随机推荐

  1. JavaScript 测试教程–part 3:测试 props,
  2. 服务端指南 数据存储篇 | MySQL(09) 分库与
  3. 迈向 serverless 开发的第一步[每日前端
  4. android中导入低版本project
  5. package.json 详解[每日前端夜话0xEF]
  6. 聊聊 Redis 使用场景
  7. 04 管道、重定向和环境变量
  8. Selenium3自动化测试【12】元素定位认知
  9. Java面试题全集(6)
  10. 23 个初级 Vue.js 面试题[每日前端夜话0x