界面如下


Android文件读写简单示例_第1张图片

package org.snailteam;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;public class FileSave extends Activity {private EditText text;private Button save, reader;protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.fileui);text = (EditText) findViewById(R.id.editText1);save = (Button) findViewById(R.id.buttonSave);reader = (Button) findViewById(R.id.reader);save.setOnClickListener(new OnClickListener() {public void onClick(View view) {OutputStream os = null;try {os = openFileOutput("textMe", MODE_PRIVATE);os.write(text.getText().toString().getBytes());} catch (FileNotFoundException e) {} catch (IOException e) {} finally {try {os.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}text.setText("");}});reader.setOnClickListener(new OnClickListener() {public void onClick(View arg0) {text.setText("");InputStream is = null;byte[] b = null;try {is = openFileInput("textMe");b = new byte[1024];int length = is.read(b);text.setText(new String(b));} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{try {is.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}});}}

更多相关文章

  1. Android读写文件示例
  2. Android 的网络编程(5)-通过ksoap2调用webservice示例
  3. android 登陆界面
  4. android 滑动欢迎界面
  5. Android 主界面 九宫格 超灵活的配置
  6. Android情景模式、文件管理器 完整示例编程详解、Android程序优
  7. Android 监听Fragment界面的点击事件
  8. android 模拟软件启动界面
  9. Andoid - 开发实例(2): ViewPager卡片式界面2

随机推荐

  1. Android(安卓)自定义View之自定义评分选
  2. Android工程直接调用monkey源码进行压力
  3. Android(安卓)ApiDemos示例解析(95):View
  4. Realm for Android(安卓)简单使用
  5. Cocos2d-x 3.2编译生成Android程序出错的
  6. Eclipse 默认打开Android(安卓)xml 布局
  7. Android(安卓)ActionBar返回父级Activity
  8. Android(安卓)GPS应用:动态获取位置信息
  9. 【转】高通平台android 环境配置编译及开
  10. XDebuggable&mprop代码分析