How to make csv file password protected in android
I need to create a开发者_运维问答nd read password protected csv file in android .
Is it possible with android ??
IF not then is there any other file formate which is password protected with android ??
Is there any solution for ??
Thanks in advance.
There is no way to password protect a .csv file, in Android or any other platform. .CSV files are plain text and any form of password protection would make them another format altogether and they would become unreadable in any other software.
Your best bet would probably be to try to output to a proprietary file format (for example, .xls) and use the password protection provided there.
This has other problems in that you will need to locate the necessary libraries to produce that file type, and you may need to be licensed to create those files. Plus, the password protection on files is notoriously weak so you cannot guarantee that the password would prevent anybody from reading the contents.
So, in short - you cannot do what you want with .csv files.
EDIT:
How to encrypt and decrypt file in Android? seems to have a couple of examples on how to encrypt/decrypt files in Android, though the question is - will you need to share this file with other systems?
Your question isn't clear on this point but if you do not, then just use getExternalFilesDir() for an encrypted location on the external SD card, or getFilesDir() for your private file location on the internal memory, which would both serve to limit access to the file to just your application.
The benefit of using the above functions is that you do not need to do anything special to access the file - just open and read/write it as you would any other file.
If you did need to share the file, a simple export function could be written.
I have created one for my own purpose, please click here.
Usage Example
String password = "your_password";
encrypter.encrypt(new FileInputStream(src),new FileOutputStream(dst),password);
You would have to think in terms of encryption.
精彩评论