In Android, would it be possible to open a file in the 'values' folder and to read its content?

76 views Asked by At

For a unit test, I want to open programatically colors.xml and strings.xml from the 'values' folder, in order to compare the entries with those from other files. I tried something like this:

    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);

It doesn't work - "not OK".

1

There are 1 answers

0
Marcin Orlowski On BEST ANSWER

There's no colors.xml nor strings.xml nor even res/ folder in APK. It's source folder and is not bundled in the app but it used to build one. So you cannot have this opened and read as regular file.