IO流,外部与内部文件的读写,API寻找到文件,外部读写权限
来源:互联网 发布:怎么样求助网络捐款 编辑:程序博客网 时间:2024/05/18 12:43
public class MainActivity extends Activity {
private EditText et_name;
private EditText et_pass;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et_name = (EditText) findViewById(R.id.et_name);
et_pass = (EditText) findViewById(R.id.et_pass);
readAccount();
}
public void readAccount(){
//1、这个就是找到该文件,通过API来获取路径
File file = new File(getFilesDir(), "info.txt");
// 2、当手机内部存储空间不足的时候,会清除掉缓存的数据,这个创建出来的文件会消失
File file = new File(getCacheDir(), "info.txt");
if(file.exists()){
try {
FileInputStream fis = new FileInputStream(file);
//把字节流转换成字符流
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
//读取txt文件里的用户名和密码
String text = br.readLine();
String[] s = text.split("##");
et_name.setText(s[0]);
et_pass.setText(s[1]);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void login(View v){
String name = et_name.getText().toString();
String pass = et_pass.getText().toString();
CheckBox cb = (CheckBox) findViewById(R.id.cb);
//判断选框是否被勾选
if(cb.isChecked()){
//返回一个File对象,其路径是data/data/com.itheima.apirwinrom/files
// File file = new File(getFilesDir(), "info.txt");
//返回值也是一个File对象,其路径是data/data/com.itheima.apirwinrom/cache
File file = new File(getCacheDir(), "info.txt");
FileOutputStream fos;
try {
fos = new FileOutputStream(file);
fos.write((name + "##" + pass).getBytes());
fos.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//创建并显示吐司对话框
Toast.makeText(this, "登录成功", 0).show();
}
}
外部内存权限 权限在清单控制文件中,读权限read_EXTERAN_XXXXX 写权限write_EXTERAN_XXXXX
通过API得到外部内存文件的路径 File file = new File(Enviroment.getExternalStorageDireotory(), "info.txt");
0 0
- IO流,外部与内部文件的读写,API寻找到文件,外部读写权限
- Android中外部,内部文件读写
- 外部存储读写文件
- 使用C#读写外部的资源文件
- android 学习笔记2-logcat 内外部文件的存储 文件权限 xml读写
- Android文件读写操作(assets 文件、 raw文件、内部存储文件、外部存储文件)
- IO流的文件读写
- 文件的读写,io流
- 在外部存储中读写文件
- 2、文件读写、外部存储、Xml备份
- Android -- 读写文件到内部ROM,SD卡,SharedPreferences,文件读写权限
- Android_02_在内部或外部存储中读写文件的操作
- IO与文件读写---Java的IO流架构
- IO与文件读写---Java的IO流架构
- IO与文件读写---Java的IO流架构
- 使用API获取内部存储文件的路径;外部存储
- IO流读写文件
- IO 流读写文件
- sharedPreferences 读取存储零散的数据
- 检测SD卡的状态与SD卡的剩余容量
- 哈希分布与一致性哈希算法简介
- ios runtime IMP指针 消息转发机制
- Java多线程与并发(四)之中断线程
- IO流,外部与内部文件的读写,API寻找到文件,外部读写权限
- memcache的一致性hash算法使用
- Solaris 指令两则
- 事件拦截,父控件和子控件
- 面向对象之魔术方法__get()和__set()
- caffe的层结构可视化工具
- js/jQuery判断浏览器名称、内核版本、浏览器壳
- memcache经典介绍
- 按钮,下一个或者上一个