开发者

Distributing files with an Android application

I wanted to build an application that would have its own database. I know that LiteSQL can be used, but apart from that I am allowed开发者_C百科 to use standard file system using FileInputStream and FileOuputStream.

I know I can create file with FileOutputStream and it will get written to /data/data/com.mydomain/files/ directory. I also know that once the file is written it's going to stay there and it will be available for reading next time the application runs.

My question is: how can I distribute the file with the application? I don't want to be forced to create the file during the first run of the application. I would rather create it before the application gets packaged.

In fact, if I decided to use LiteSQL instead, I would face similar problem. Right?

Thanks in advance,

M.K.


You can place any resources that do not need to be compiled in to the /res/raw directory.

You could place your file in there and on the first run of the app read the file using the getResources().openRawResource() method and then write the contents into a file on the device.

In the past I have used a database dump file from the /res/raw directory to do an initial population of a database (this can be time consuming if you have a lot of data to insert though). It might be possible to put the actual SQLite database file in there, which you could just copy to the device.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜