android - 找不到“Src”作为文件或资源。在 PdfReader 阅读器 = 新 PdfReader(src)
问题描述
我正在尝试使用密码加密 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 未作为文件或资源找到。
解决方案
推荐阅读
- javascript - JavaScript dispatchEvent 未调度
- python - Python - 使用 Schedule 每天同时从数据库中填充数据
- amazon-web-services - 如何在不使用 ELB 服务的情况下使用 kops 在 AWS 上创建 Kubernetes 集群?
- dart - 覆盖 analysis_options.yaml 中的值
- javascript - Fetch API - Content-Type 在设置为 application/json 时以 text/plain 形式发送
- mule - 选择设计中心位置时,Mulesoft 错误添加 API 实现
- python - 熊猫在可能的情况下使行变平
- c - 随机太阳系模拟碰撞检测问题
- ios - iOS App 在 iOS 12 上的编译器生成代码中崩溃
- java - 如何结束连续接受字符的while循环