1

我正在尝试将 PDF 文件保存到外部存储目录。我想我遗漏了一些明显的东西,所以也许我们可以一起解决这个问题。

首先,我单击保存按钮并检查目录是否存在。

File direct = new File(Environment.getExternalStorageDirectory() + "/CompanyName");

//if directory does not exist then create it
if (!direct.exists()) {
    filedir.mkdirs();
} 

然后我需要保存 PDF 文件。我的应用程序设置方式我已将 PDF 下载到我的 PDF 查看器中,因此我可以直接访问该文件。我想我在这里遗漏了一个关键概念,但大多数在线答案都是针对图像或创建文本文件的。

pdfFile = new File(direct, imageTitle.getText().toString());

try {
    //try to create a new file
    pdfFile.createNewFile();

} catch (IOException e) {
     e.printStackTrace();
}
4

0 回答 0