【问题标题】:In Android, would it be possible to open a file in the 'values' folder and to read its content?在 Android 中,是否可以在“values”文件夹中打开文件并读取其内容?
【发布时间】:2015-06-08 08:30:52
【问题描述】:

对于单元测试,我想以编程方式从“values”文件夹中打开 colors.xml 和 strings.xml,以便将条目与其他文件中的条目进行比较。 我尝试过这样的事情:

    String fileName = "res/strings.xml";
    ClassLoader classLoader = getClass().getClassLoader();
    File f = new File(classLoader.getResource(fileName).getFile());

    if(f.exists()) {
        System.out.println("OK");
    } else {
        System.out.println("not OK");
    }
    Assert.assertNotNull(f);

它不起作用 - “不正常”。

【问题讨论】:

    标签: android file path


    【解决方案1】:

    APK 中没有 colors.xmlstrings.xml 甚至 res/ 文件夹。它是源文件夹,未捆绑在应用程序中,但它用于构建一个。所以你不能把它作为普通文件打开和读取。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-23
      • 1970-01-01
      • 1970-01-01
      • 2019-02-17
      • 1970-01-01
      • 2013-06-14
      相关资源
      最近更新 更多