Marek
Marek

Reputation: 4081

How to get reference to a file inside a package

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

Upvotes: 1

Views: 1646

Answers (1)

Bishan
Bishan

Reputation: 15720

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");

Upvotes: 2

Related Questions