首页 > 解决方案 > 找不到“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 未作为文件或资源找到。

标签: androiditext

解决方案


推荐阅读