Rajat
Rajat

Reputation: 1447

Get a reference to a file saved at compile time

I have a text file which I'll be using to populate my database. The easiest way I found to use this file is using .import statement of SQLite. The statement will be something like this.

.import  <myFileName>  <myTableName>

However, I don't know where to save this text file. The most basic choice is res/raw folder. But then how to get a reference to this File ?

I must emphasize on the fact that I want a reference of the file and not read it.

Thanks.

Upvotes: 2

Views: 128

Answers (1)

dst
dst

Reputation: 3337

You can in general cannot get real file handles of files that do not exist. Ressources and Assets are compiled into your apk, and thus no regular files.


If you wish to ship your application with a database, you can use the asset folder. There is a related question about that. The basic method is that you create the whole database at compile-time (using some tool for sqlite databases, for example SQLite database browser) and ship that database file as asset. Then you can extract the database file from assets and use the newly created database file.

Upvotes: 2

Related Questions