How to get reference to a file inside a package

2019-06-05 12:58发布

I have file kanji.xls. I would like to get that file through new File(); What should I write inside that constructor? I tried many options but didn't find correct answer...

enter image description here

I tried:

  1. /kanji.xls
  2. /Kanji database/kanji.xls
  3. //Kanji database//kanji.xls
  4. kanji.xls

1条回答
甜甜的少女心
2楼-- · 2019-06-05 13:28

Use assets directory in your project to store this file and read file from there. Android – Read file from Assets will guide you.

if you don't wish to use assets directory,

Create directory as Kanji_Database instead of Kanji database. Then use below code.

File f= new File(Environment.getExternalStorageDirectory()
            + "/Android/data/" + getApplicationContext().getPackageName()
            + "/Kanji_Database/", "kanji.xls");
查看更多
登录 后发表回答