向内置存储卡内写入和读出文件
来源:互联网 发布:苹果mac常用软件 编辑:程序博客网 时间:2024/06/04 23:34
先看代码
public class sdcard extends Activity{ private EditText editText; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.sdcardlayout); editText = (EditText) findViewById(R.id.editText2); /* Button button = (Button) findViewById(R.id.button5); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(sdcard.this,"sdsfd",Toast.LENGTH_SHORT); } });*/ } public void read(View view) { try { File file = new File("/data/data/com.example.zhao.menu/files/config.txt"); FileInputStream in = new FileInputStream(file); int length = in.available(); byte[] buffer = new byte[length]; in.read(buffer); String str = new String(buffer); Toast.makeText(sdcard.this,str,Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public void write(View view) { try { FileOutputStream out = sdcard.this.openFileOutput("config.txt", Context.MODE_APPEND); String str = editText.getText().toString(); out.write(str.getBytes()); out.flush(); out.close(); Toast.makeText(sdcard.this,str,Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); } /* File file=new File(Environment.getExternalStorageDirectory(), "log.txt"); OutputStream out= null; try { out = new FileOutputStream(file); String str = "dsfsdfsdfds"; out.write(str.getBytes()); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }*/ }
要注意写好的文件存储在
/data/data/包名/files/文件名
0 0
- 向内置存储卡内写入和读出文件
- 向文件里面写入和读出含有中文的例程
- MFC 向txt文件写入和读出汉字
- 向一个文件写入信息并读出写入另一个文件
- mysql文件写入和读出数据库
- excel文件的读出和写入
- java简单读出和写入txt文件
- fprintf(); fscanf(); 向文件中写入读出数据
- INF文件写入读出
- 写入、读出文件
- c#写入文件读出文件
- Python学习--文件和存储器的写入和读出实例
- Python学习--文件和存储器的写入和读出实例
- java控制excel文件的 写入和读出操作
- 文件读出和写入两种基本方法
- 日志处理(文件的读出和写入)
- 文件的写入与读出
- 体验文件写入/读出--char3
- NUC1178 Kickdown
- c++ socket 模拟 http
- Drawlayout 抽屉 禁用滑动
- C语言介绍
- 网络图片浏览器
- 向内置存储卡内写入和读出文件
- 使用IText实现office Word文档导出
- 结构体类型在定义变量时,其前可以省略
- 动态控制线程池中正在运行的任务
- 安装Cloudera Manager Server和Agent过程中遇到的问题
- spring-boot Hello World
- leetcode 495. Teemo Attacking
- 如何让img在div中居中
- MyEclipse+Tomcat+MAVEN+SVN项目完整环境搭建