How to store a PDF file in SQLite Data base in Android

帅比萌擦擦* 提交于 2020-01-24 20:46:07

问题


Actually, I want to download a PDF file in our Android phone and don't want to give the permission to open the PDF file in PC when he try to open by connecting the Phone to PC. so I want to go with storing the PDF file in SQLite Data Base solution.

My question is...
Is it possible to store PDF file in SQLite database? If yes, how? Or is there any other way to implement same functionality?

Please Help me...

Thanks...


回答1:


You can. Simply read all the bytes of the pdf file and store in the blob field of sqlite db.




回答2:


One solution is to use blob and to store the raw data of the file as column in the db.

Other solution which i think is better to store the files on the Internal Storage and in the db just to store the file paths. Internal storage is private for your application so no one will have access to the files. But be careful in both cases the files are stored on the phone storage and people can find themselves in situation when there is no more phone storage.




回答3:


AFAIK Sqlite support the BLOB datatype, I used BLOB for store images into MySql databases, I think you can do the same thing reading the file content and storing that into a BLOB column in SQLite




回答4:


You can use a BLOB datatype to store a PDF file in the database but that wouldnt be my suggestion since you are using SQLlite tough its possible. Some people say it's a dirty way to store binary files in a database. Large databases will result in slower queries.

My solution would be to store a PDF file in a directory and use a string pointer to the file name. This will result in faster queries and a smaller database. Only downside is that you have to write functionality to rename duplicate entries and delete files from the file system when you delete an entry.

Please comment if (large) binary files in databases make the database slower...



来源:https://stackoverflow.com/questions/5788890/how-to-store-a-pdf-file-in-sqlite-data-base-in-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!