首页 技术 正文
技术 2022年11月15日
0 收藏 418 点赞 3,101 浏览 1905 个字
public class DataActivity extends Activity {
private EditText filenameText;
private EditText contentText;
private TextView resultView;
private static final String TAG = "DataActivity";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
filenameText = (EditText) this.findViewById(R.id.filename);
contentText = (EditText) this.findViewById(R.id.content);
resultView = (TextView) this.findViewById(R.id.result);
String filename = filenameText.getText().toString();
Button button = (Button) this.findViewById(R.id.button);
Button showButton = (Button) this.findViewById(R.id.showButton);
button.setOnClickListener(listener);
showButton.setOnClickListener(listener);
}
private View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View v) {
Button button = (Button) v;
String filename = filenameText.getText().toString();
switch(button.getId()){
case R.id.button://如果是保存按钮
int resId = R.string.success;
String content = contentText.getText().toString();
try {
OutputStream outStream = DataActivity.this.openFileOutput(filename, Context.MODE_WORLD_WRITEABLE+Context.MODE_WORLD_READABLE);
//四中操作模式
//Context.MODE_PRIVATE=0 覆盖、私有
//Context.MODE_APPEND=32768追加、私有
//Context.MODE_WORLD_READABLE=1其他的程序可以访问
//Context.MODE_WORLD_WRITEABLE=2
try {
FileService.save(outStream, content);//保存文件
} catch (Exception e) {
Log.e(TAG, e.toString());
resId = R.string.error;
}
} catch (FileNotFoundException e) {
Log.e(TAG, e.toString());
resId = R.string.error;
}
Toast.makeText(DataActivity.this, resId, Toast.LENGTH_LONG).show();
break;
case R.id.showButton://如果是显示按钮
try {
InputStream inStream = DataActivity.this.openFileInput(filename);
String text = FileService.read(inStream);
resultView.setText(text);
} catch (Exception e) {
Log.e(TAG, e.toString());
resId = R.string.error;
Toast.makeText(DataActivity.this, "读取失败", Toast.LENGTH_LONG).show();
}
break;
}
}
};
} //本文出自 “阿凡达” 博客,请务必保留此出处http://shamrock.blog.51cto.com/2079212/702531
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,023
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,513
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,360
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,143
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,774
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,852