Android 中的文件存储
来源:互联网 发布:rtl8152b linux驱动 编辑:程序博客网 时间:2024/05/23 21:59
package cn.tttt.android_file;import java.io.BufferedOutputStream;import java.io.BufferedReader;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStreamReader;import android.app.Activity;import android.os.Bundle;import android.util.Log;public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); String word = readFromFile(); Log.i("tttt", "word -> " + word); } public String readFromFile() { StringBuffer result = new StringBuffer(); FileInputStream fis = null; InputStreamReader isr = null; BufferedReader br = null; try { fis = openFileInput("helloworld.txt"); isr = new InputStreamReader(fis); br = new BufferedReader(isr); int b; while((b = br.read()) != -1) { result.append((char) b); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if(br != null) { try { br.close(); br = null; } catch (IOException e) { e.printStackTrace(); } } } return result.toString(); } public void writeToFile() { FileOutputStream fos = null; BufferedOutputStream bos = null; String word = "public static void main(String[] args)"; try { fos = openFileOutput("helloworld.txt", MODE_PRIVATE); bos = new BufferedOutputStream(fos); bos.write(word.getBytes()); bos.flush(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (bos != null) { try { bos.close(); bos = null; } catch (IOException e) { e.printStackTrace(); } } } }}
0 0
- Android中的文件存储
- Android中的文件存储
- Android 中的文件存储
- Android中的文件存储
- Android中的文件存储技术
- Android中的文件存储目录
- Android文件存储中的坑
- Android中的文件存储安全
- Android中的文件存储问题
- Android 中的数据存储----文件存储
- Android中的文件存储数据方式
- Android中的文件存储数据方式
- Android中的文件存储数据方式 .
- android中的文件存储操作总结
- Android中的文件存储数据方式
- Android中的文件存储outFileOutput和openFileInput
- Android中的文件存储数据方式
- Android中的文件存储和sharedpreference
- C#利用最新版的WPS实现导入导出
- 使用C#写WPS的excel 使用“WPS表格”导出Excel文档
- 对于json格式数据节点的解析
- python中的map、filter、reduce函数
- 对于文件下载
- Android 中的文件存储
- TexturePacker 4.X 在Cocos2d-x 3.x 中帧动画实现(官方文档)
- spark-shell 启动 以及 例子
- gdb调试程序1
- SortedNmaePrice节省内存解法代码实现
- iOS 【UIKit-程序启动原理/UIWindow加载】
- python练习-工资计算器
- sublime用浏览器打开方法
- springSecurity集成cas