4

I want to make a dedicated folder to hold CSV files, much like there is a dedicated folder for drawables, for layouts, for menus, for mipmaps, for values, for xml, etc. I want to make one called "csv".

However when I right click the res folder, there are so many new folder options. When I do New Directory by itself, it doesn't seem to show up in Android view. Do I need to do New Android resource directory? Or down below in the Android folder table dropdowns where I can make a new Assets Folder, Java Folder, Java Resources Folder, Res Folder, etc?

AJJ
  • 2,004
  • 4
  • 28
  • 42

1 Answers1

3

I want to make one called "csv".

That will not work. You cannot invent new resource types. Put them in assets/ (or an assets/csv/ directory, if you prefer), or in a raw resource directory.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 1
    I don't see an assets or a raw directory? I am using Android Studio (as opposed to Eclipse) if that has any impact on anything. – AJJ Mar 29 '16 at 15:57
  • 2
    @ArukaJ: You are welcome to create an `assets/` directory as a peer of `res/`, by right-clicking on your sourceset (e.g., `main`) and choosing New > Directory. You are welcome to create a `raw/` directory, by right-clicking on `res/` and choosing either New > Directory or New > "Android resource directory". If you go with "Android resource directory", choose `raw` as your "Resource type". – CommonsWare Mar 29 '16 at 16:00
  • So I can either make a peer `assets` folder (i.e. alongside `res`) or `res/raw`? Is there a difference between these two? – AJJ Mar 29 '16 at 16:05
  • @ArukaJ, follow [this](http://stackoverflow.com/questions/26706843/adding-an-assets-folder-in-android-studio) SO post to learn how to create an assets directory in Android Studio – Sajib Acharya Mar 29 '16 at 16:09
  • From what I can Google here it looks like the tradeoff is that `assets` will let me make directory substructures inside it, but I lose access to getting ID's via referencing `R`. But if I put them in `res/raw`, access is faster and I gain access to the `R` reference, but lose the ability to make directory substructures. Is this right? – AJJ Mar 29 '16 at 16:09
  • @CommonsWare What would you recommend is a better place to put the .csv file? More appropriate for assets or res/raw? – AJJ Mar 29 '16 at 16:12
  • 1
    @ArukaJ: "Is this right?" -- more or less. I think that you over-emphasize the value of the `R` constant. Personally, I use `assets/`, unless I need different files for different configurations (e.g., different CSV files for different languages). In that case, having multiple resource directories is a win (e.g., `res/raw/`, `res/raw-es/`, `res/raw-zh/`), with Android choosing the right one at runtime. – CommonsWare Mar 29 '16 at 16:16
  • Perhaps I misunderstand, but does that imply I could theoretically make a `res/raw-csv` folder? Any folder I want as long as it has the `raw` prefix? – AJJ Mar 29 '16 at 16:18
  • @ArukaJ: No, because you cannot invent new configurations. The `res/` directory structure is defined by Android; you merely choose which directories to bother with. `assets/`, on the other hand, is completely free-form -- you can have any structure you want in there that works for you. – CommonsWare Mar 29 '16 at 16:19
  • I ask because I just found http://developer.android.com/guide/topics/resources/providing-resources.html but don't see anything about allowing additional suffixes on the `raw` name. Edit: Nevermind yes I do, I understand now. Thanks. I'll go with assets. Good excuse to learn how to use AssetManager! – AJJ Mar 29 '16 at 16:20
  • @ArukaJ: The qualifiers are valid for all resource types. *Usually*, languages only are applied to `res/values/`, because *usually* the only strings you have are in `res/values/`. However, in your case, I could imagine that you might be getting CSV files from something else, with different CSV files for different locales, which is why I mentioned it as a decision criterion. – CommonsWare Mar 29 '16 at 16:21