复制代码
1
2
3
4
5
6
7
8
9
10
11
12<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_horizontal"> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="生成私有文件" android:onClick="getPrivateFile"/> </RelativeLayout>
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29package com.example.siyouwenjian; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Toast; public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void getPrivateFile(View view){ try { File file=new File(getFilesDir(),"private.txt"); FileOutputStream fos=new FileOutputStream(file); fos.write("private".getBytes()); fos.close(); Toast.makeText(this, "保存数据成功", 0).show(); } catch (Exception e) { Toast.makeText(this, "保存数据失败", 0).show(); }; } }
最后
以上就是聪慧月饼最近收集整理的关于Android之生成私有文件的全部内容,更多相关Android之生成私有文件内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复