0

I make some small app that should load some data.xml file. I would like to put this in data\data.xml.
But where should i put it in my Android prject (i use Eclipse)?
When i try to make directory data under assets or res, compiler complains this is invalid directory name.
And then how to call this directory path (i run it under emulator which has own environment)?

rainbow
  • 1,161
  • 3
  • 14
  • 29

1 Answers1

3

It is not allowed to create your own folder inside the res folder. this folder is reserved for Layouts and other Android specific resources (xml-defined Arrays, Strings, etc.).

But creating a folder inside the assets folder is working fine in my project and should be the default way to ship files with your bundled App.

Read this answer to see how to access files within the assets folder from your Activity. You need to call Activity.getAssets()

Community
  • 1
  • 1
Simulant
  • 19,190
  • 8
  • 63
  • 98
  • I had to clean project and compiler stop complains about data directory. And what if i would like to have an access from standard class? Should i pass activity to it or there is some other way (more Java-like)? – rainbow Dec 04 '13 at 13:26
  • If it is sure that your Class accesses the assets, after the Activity is started you could hand over a (static) link to the context like in the answer: http://stackoverflow.com/a/5114361/1515052 – Simulant Dec 04 '13 at 13:31
  • I will precise my question, is it possible to get file like this: File file = new File("some path"); BufferedReader reader = new BufferedReader(new FileReader(file)); – rainbow Dec 04 '13 at 14:32