简体   繁体   中英

Accessing non-android xml file in android project

Usually I can put an xml-file (of non-android format, the same would be if I need, fe, to use .txt file) into my project directory and use it by

  File file = new File("init.xml");

This doesn't work with android project, so I need a solution.

PS Asset manager doesn't work in this case, because I need to work exactly with a field of File type, but AM only provides the following method

InputStream open(String fileName);

将它放在您的res文件夹中并使用R.foo.bar访问它。文件的路径。

我相信您可以将文件放在资源路径中,并使用类似以下内容来访问它

InputStream is = context.getResources().openRawResource(R.xml.myfile);

Where did you put your file? I think it'll work if you put it in a "raw" folder in your project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM