zoukankan      html  css  js  c++  java
  • res/raw下的资源文件读写

    读取原始格式文件,首先需要调用getResource()函数获得资源对象,然后通过调用资源对象的openRawResource()函数,以二进制流的形式打开指定的原始格式文件。在读取文件结束后,调用close()函数关闭文件流
    关于读取原始格式文件的核心代码如下

    Resources resources = this.getResources();
    InputStream inputStream = null;
    try {
     inputStream = resources.openRawResource(R.raw.raw_file);   
     byte[] reader = new byte[inputStream.available()];
     while (inputStream.read(reader) != -1) { 
     }

    自己整理的:

    View Code
     1 Resources resources = this.getResources();//在住程序初始化的时候得到资源文件         
    2 InputStream inputStream = null; //得到输入流
    3 try {
    4 inputStream = resources.openRawResource(R.raw.raw_file);//以二进制流的形式打开指定的原始格式文件
    5 byte[] reader = new byte[inputStream.available()]; //把得到的流数据存放在reader里面
    6 while (inputStream.read(reader) != -1) { //一直读到最后
    7 }
    8 displayView.setText(new String(reader,"utf-8")); //显示在EditText里面
    9 } catch (IOException e) {
    10 Log.e("ResourceFileDemo", e.getMessage(), e);
    11 } finally {
    12 if (inputStream != null) {
    13 try {
    14 inputStream.close(); //关闭输入流
    15 }
    16 catch (IOException e) { }
    17 }
    18 }

     这个app潮流公众帐号主要是推荐给手机用户最近最潮的软件,让大家随时跟上时尚。我们会提供给你们最好的服务,喜欢我们就帮我们推荐吧!

  • 相关阅读:
    在线支付模块小结
    Tomcat服务器热启动,修改项目源代码时不需要每次都重启Tomcat
    使用myeclipse进行hibernate快速开发
    hibernate的核心类和接口
    Hibernate手动配置
    Java的字符串md5加密和文件md5
    JDBC操作mysql数据库(SqlHelper类封装)
    yum报错[Errno 14] PYCURL ERROR 22(更换yum源)
    Ajax技术
    手动配置开发struts项目
  • 原文地址:https://www.cnblogs.com/shaoyangjiang/p/2390612.html
Copyright © 2011-2022 走看看