1,读取assets文件夹中的数据:

try {
InputStream is = getResources().getAssets().open("info.txt");
InputStreamReader reader = new InputStreamReader(is, "UTF-8");
BufferedReader bufferedReader = new BufferedReader(reader);
String line = "";
while ((line=bufferedReader.readLine())!=null)
Log.d("===", "readLine:"+line);
} catch (IOException e) {
e.printStackTrace();
}


2,读取raw文件夹中的数据:

InputStream is = getResources().openRawResource(R.raw.info);
InputStreamReader reader = null;
try {
reader = new InputStreamReader(is, "UTF-8");
BufferedReader bufferedReader = new BufferedReader(reader);
String line = "";
while ((line=bufferedReader.readLine())!=null){
Log.d("===", "readLine:"+line);
}
}catch (IOException e) {
e.printStackTrace();
}


3,写内部存储的文件数据(文件保存在data/data/包名/file 下)

try {
                        FileOutputStream fos = openFileOutput(fileName, MODE_PRIVATE);
                        OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
                        osw.write(数据);
                        osw.flush();
                        fos.flush();
                        osw.close();
                        fos.close();
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }


4,读内部存储的文件数据(文件路径:data/data/包名/file 下)


try {
                    FileInputStream fis = openFileInput(fileName);
                    InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
                    char[] input = new char[fis.available()];
                    isr.read(input);
                    isr.close();
                    fis.close();
                    String result = new String(input);
                    
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }






更多相关文章

  1. mybatisplus的坑 insert标签insert into select无参数问题的解决
  2. python起点网月票榜字体反爬案例
  3. NPM 和webpack 的基础使用
  4. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
  5. 读取android手机流量信息
  6. android 使用html5作布局文件: webview跟javascript交互
  7. 《Android开发从零开始》——25.数据存储(4)
  8. Android(安卓)多媒体扫描过程(Android(安卓)Media Scanner Proces
  9. Android系统配置数据库注释(settings.db)

随机推荐

  1. Android(安卓)WebView中javascript和java
  2. Android之父深入解析Android
  3. eoe android客户端源码剖析(一)动画启动界
  4. Android(安卓)计时器Timer用法
  5. Android(安卓)调试:java 跨工程调试 andro
  6. android 播放rtsp协议流媒体
  7. 第四章 Android开发三大基石—Activity、
  8. 修改Android工程版本
  9. Cocos2d-x shareSDK
  10. Google工程师解析Android系统架构