相关疑难解决方法(0)

访问Android中的资源文件

我在/ res/raw /文件夹(/res/raw/textfile.txt)中有一个资源文件,我试图从我的Android应用程序中读取进行处理.

public static void main(String[] args) {

    File file = new File("res/raw/textfile.txt");

    FileInputStream fis = null;
    BufferedInputStream bis = null;
    DataInputStream dis = null;

    try {
      fis = new FileInputStream(file);
      bis = new BufferedInputStream(fis);
      dis = new DataInputStream(bis);

      while (dis.available() != 0) {
              // Do something with file
          Log.d("GAME", dis.readLine()); 
      }

      fis.close();
      bis.close();
      dis.close();

    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Run Code Online (Sandbox Code Playgroud)

我尝试了不同的路径语法但总是得到java.io.FileNotFoundException错误.如何访问/res/raw/textfile.txt进行处理?是File file = new File("res/raw/textfile.txt"); Android中的错误方法?


*答案: …

java resources android file

33
推荐指数
1
解决办法
8万
查看次数

标签 统计

android ×1

file ×1

java ×1

resources ×1