8.读取外部存储文件
来源:互联网 发布:淘宝商品描述图片尺寸 编辑:程序博客网 时间:2024/05/22 13:05
Environment.getExternalStorageDirectory()获取存储卡的路径
有4种状态:
MEDIA_UNKNOWN:不能识别sd卡
MEDIA_REMOVED:没有sd卡
MEDIA_UNMOUNTED:SD卡存在但是没有挂载
MEDIA_CHECKING:sb卡正在准备
MEDIA_MOUNTED:sd卡已经挂载,可以用
有4种状态:
MEDIA_UNKNOWN:不能识别sd卡
MEDIA_REMOVED:没有sd卡
MEDIA_UNMOUNTED:SD卡存在但是没有挂载
MEDIA_CHECKING:sb卡正在准备
MEDIA_MOUNTED:sd卡已经挂载,可以用
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); read(); } //读取文件 public void read(){ //使用api读取路径 //File file = new File("sdcard/12.txt"); File file = new File(Environment.getExternalStorageDirectory(),"123.txt"); if(file.exists()){ try { FileInputStream fis = new FileInputStream(file);//把字节流转换成字符流BufferedReader br = new BufferedReader(new InputStreamReader(fis));//读取txt里面的数据,readLine可以读取一行数据String text = br.readLine();String[] s = text.split("=="); et_name.setText(s[0]); et_pass.setText(s[1]); fis.close(); br.close();} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();} } } //点击登陆写文件 public void login(View v){ CheckBox cb = (CheckBox) findViewById(R.id.cb); String name = et_name.getText().toString(); String password = et_pass.getText().toString(); if(cb.isChecked()){ //data/data/com.ldw.rwinrom:存储空间的路径 //File file = new File("sdcard/12.txt"); File file = new File(Environment.getExternalStorageDirectory(),"123.txt"); try { FileOutputStream fos = new FileOutputStream(file);fos.write((name + "==" + password).getBytes());fos.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} } Toast.makeText(this, "登陆成功", Toast.LENGTH_SHORT).show(); }
0 0
- 8.读取外部存储文件
- 读取外部存储的文件数据
- 读取外部存储的文件数据Environment.getExternalStorageDirectory()
- 外部文件读取
- 数据存储-读取外部数据
- 外部存储读写文件
- flash读取外部TXT文件
- flash读取外部txt文件
- Unity3d 动态读取外部文件
- Unity3d 动态读取外部文件
- Unity3d 动态读取外部文件
- 读取jar包外部文件
- 外部表读取跟踪文件
- Unity3d 动态读取外部文件
- andriod之ContentProvider读取外部存储图片
- 文件管理 内部存储 外部存储 Sdcard
- android 文件存储读取
- Android从外部存储设备中读取,或存储数据
- CY_经验001
- Django 学习,异常解决记录
- first head html css 读书笔记
- python-
- [贪心]删数问题
- 8.读取外部存储文件
- php+mysql (解决post提交数据受限1000条)
- 机器学习入门笔记
- R中类型转换函数
- 常见的几种排序算法-插入、选择、冒泡、快排、堆排等
- 三表联级查询
- ViewDragHelper
- 基于STM32的DS18B20驱动
- 京东首页之nav导航栏、banner广告部分、footer备案号