0

我想将 string.xml 文件原样复制到 sdcard。但我无法获得任何方法来做到这一点。我想做这样的事情。

代码:

File f = 某种加载 string.xml 文件的方法,例如 new File("file path") 或 getResource M method()。

然后复制到 SD 卡的代码。

我无法创建 string.xml 的文件对象。

请帮助我。

提前致谢....

凯坦·班格尔

4

1 回答 1

0

这些 xml 文件已编译,您无法直接作为输入流读入。但是,您可以加载所有字符串并将它们写入文件。

Field[] allStrings = R.string.class.getFields();
    for(int i = 0; i < allStrings.length; i++) {
        try {
            String str = getResources().getString(allStrings[i].getInt(null));
            // write it to file or Do what you need to do.
        } catch (NotFoundException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
于 2013-04-29T07:47:13.170 回答