Android对文件的保存操作
来源:互联网 发布:数据精度 英文 编辑:程序博客网 时间:2024/06/07 01:51
1.文件可以保存在手机内存中,也可以保存在SD卡上面,保存在SD卡上要申请读写SDS卡权限,权限如下:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
①保存在手机上
public void saveFile(String fileName,String contentStr) throws IOException{FileOutputStream fileOutputStream=context.openFileOutput(fileName, Context.MODE_PRIVATE);fileOutputStream.write(contentStr.getBytes());}
②保存在SD卡上
public void savefile2SD(String fileNameStr, String contentStr) throws FileNotFoundException {File file=new File(Environment.getExternalStorageDirectory(), fileNameStr);OutputStream oStream=new FileOutputStream(file);byte[] data=contentStr.getBytes();try {oStream.write(data);} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{try {oStream.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}
关于界面,以前见到淘宝上面输入框里面有提示文字,然后鼠标点进去后文字消失,等待用户输入的效果
<EditText android:id="@+id/fileNameID" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入文件名称">
android:hint="请输入文件名称"------就是这样一行代码
还有就是要注意一下:在模拟器上面如果输入中文的话,那么保存后就有乱码,保存文件后导出到PC的话会发现找不到该文件
- Android对文件的保存操作
- Android中对文件保存、读取和删除操作的实现
- ANDROID对文件的操作
- ANDROID对文件的操作
- MFC对文件读取和保存的操作
- Android 对 properties文件的读写操作
- android 中对文件的操作
- Android studio对 module文件的操作
- android文件的保存
- Android 文件操作 sd卡保存文件
- Android 对像保存到文件
- 对文件的操作
- 对文件的操作
- 对文件的操作
- 对文件的操作
- 对文件的操作
- 对文件的操作
- 对文件的操作
- 深入理解SetUID
- Libsvm与Liblinear源码浅析与封装(二)
- c++多线程(一)
- 最大子序列和问题
- Linux运维日常监控的对象
- Android对文件的保存操作
- android 使用Scroller实现缓慢移动
- Debian 安装Flash插件
- 应用spring OSGI管理bean
- 【博弈&动态规划】poj2068Nim
- d-dimensional Delaunay
- gdb调试
- Java @Override报错解决办法
- 样在VS中设置编译选项(以启用OpenMP)