1

Recently I installed Android Studio, before I used Eclipse. While using Eclipse I could put all the files in Assets directory and access it using getassets method. For example:

InputStream ims = getAssets().open("textnew.txt");

Can you please advise:

  1. Where to store files in Android Studio? Should I create folders in /res directory myself and put files there. For example: res/raw/textnew.txt
  2. How to access those files? For example I need to open txt file in order to place its content to TextView. How to do it?

Thanks!

SergeiK
  • 83
  • 1
  • 11
  • The Assets directory and the getAssets() functions are not dependent on the editor. They are features of the Android SDK. This means, that in Android Studio you can add the Assets folder yourself if it is not created automatically. – Mootpoint Apr 12 '16 at 12:11
  • Advantages of using raw directory over assets is very well explained in this post - http://stackoverflow.com/questions/9563373/the-reason-for-assets-and-raw-resources-in-android. But it still depends on your requirements. – Passiondroid Apr 12 '16 at 12:12
  • Thank you for the information! – SergeiK Apr 12 '16 at 12:44

2 Answers2

3

You can still use an asset folder in Android Studio.

Create manually a folder asset in your app directory.

Using the menus : File / New / Folder / Assets Folder

I think that the only difference with Eclispe is that in Android Studio the folder is not created by default.

Guillaume Barré
  • 4,168
  • 2
  • 27
  • 50
  • Thanks! But is it a good practice to store files at Assets folder, as I did previously in Eclipse. Or there is another preferable way in Android Studio? – SergeiK Apr 12 '16 at 12:34
  • Decide to use or not the `asset` folder is not related with the editor you are using, and it's still a good practice. – Guillaume Barré Apr 12 '16 at 12:40
1

Android Studio has a nice assistant to create an asset-folder. This way it will be created in the correct location.

  1. Right Click on your project
  2. Click "New" -> "Folder" -> "Assets-Folder"
  3. Follow the assistant

Your folder should be created and will be added to your main-sourceset.

Christopher
  • 9,682
  • 7
  • 47
  • 76