我使用下面的Snippet
在android中创建.txt文件public void createTextFile(String fileName) {
try {
File notesDirectory = new File(Environment.getExternalStorageDirectory(), "Text Files");
if (!notesDirectory.exists()) {
notesDirectory.mkdirs();
}
File textFile = new File(notesDirectory, fileName);
FileWriter writer = new FileWriter(textFile);
writer.append("Sample Content");
writer.flush();
writer.close();
Toast.makeText(this, "File Created at "+textFile.getAbsolutePath(), Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
}
}
添加了以下权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
是否可以在Android中以编程方式提供该.txt文件的密码?
答案 0 :(得分:0)
你可以使用Jasypt。 http://www.jasypt.org/
在示例下面。
StrongPasswordEncryptor passwordEncryptor = new StrongPasswordEncryptor();
String encryptedPassword = passwordEncryptor.encryptPassword(userPassword);
...
if (passwordEncryptor.checkPassword(inputPassword, encryptedPassword)) {
// correct!
} else {
// bad login!
}
...encrypting and decrypting a text...
StrongTextEncryptor textEncryptor = new StrongTextEncryptor();
textEncryptor.setPassword(myEncryptionPassword);
String myEncryptedText = textEncryptor.encrypt(myText);
...
String plainText = textEncryptor.decrypt(myEncryptedText);