我正在尝试使用密码加密pdf。即使存储中存在pdf文件,也不显示其显示文件。路径也是正确的。我还包括了读写权限
private void Write() {
// Need to ask for write permissions on SDK 23 and up, this is ignored on older versions
if (ContextCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)
{
ActivityCompat.requestPermissions(MainActivity.this,
new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
}
}
public void file_manager(View view) {
myfileintent = new Intent(Intent.ACTION_GET_CONTENT);
myfileintent.setType("*/*");
startActivityForResult(myfileintent, 10);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
switch (requestCode) {
case 10:
path = data.getData().getPath();
akhil = new File(path);
break;
}
}
public void encrypt(View v){
try {
encryptPdf(Environment.getExternalStorageDirectory().getAbsolutePath()+path,path);
} catch (IOException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();
}
}
public void encryptPdf(String src, String dest) throws IOException, DocumentException {
File z=new File(src);
Toast.makeText(this, src, Toast.LENGTH_SHORT).show();
PdfReader reader = new PdfReader(src);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
stamper.setEncryption(USER, OWNER,
PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128 | PdfWriter.DO_NOT_ENCRYPT_METADATA);
stamper.close();
reader.close();
}
在android studio中运行显示此内容
W / System.err:java.io.IOException:/ storage / emulated / 0 / external_files / Download / 1484820337WBJEE数学样本论文2.pdf未作为文件或资源找到。