1

I use some class. That's constructor needs some file path that contains some files.

ex)

Komoran komoran = new Komoran("D:\program_project\lib");

Now I'm making android app. so I can't use absolute path (Because other people who download my app don't have that folder and files)

so I decide to use 'assets' folder that is maybe in APK file. So, final code is like below.

Komoran komoran = new Komoran("file:///android_asset");

but It seems like folder path is wrong(this class doesn't work). What I did wrong ?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
LKB
  • 457
  • 6
  • 16
  • 1
    Possible duplicate of [file:///android\_asset does not work](http://stackoverflow.com/questions/23954878/file-android-asset-does-not-work) – OneCricketeer Dec 01 '16 at 00:40
  • there are many tutorials available here to read data from assest example http://stackoverflow.com/questions/9544737/read-file-from-assets – Swapnil Dec 01 '16 at 00:41
  • Thanks. I understand. I read these two links. getAssets.open("filename") seems to work well. But what I need is folder path. I can't search the way. help me. – LKB Dec 01 '16 at 01:28

3 Answers3

3

This "file:///android_asset" path is used for applications which uses webview ex. cordova/phonegap. As it is part of resources because when Apk is created you can not use this path to access your assets folder. You have to work with context.getResources().getAssets().open("fileName")this code only.

Anuja Kothekar
  • 2,537
  • 2
  • 15
  • 28
2

Maybe u can add this code: context.getResources().getAssets().open("fileName"). u will get a inputstream, and u can do something u want.

hero Sun
  • 21
  • 3
0

No need to use getResources. You can use directly

context.getAssets().open("fileName").
Rahul Giradkar
  • 1,818
  • 1
  • 17
  • 28