我正在使用 itext 库,我无法在模拟器 sdcard 中编写 pdf,即使从我的角度来看我的代码似乎我找不到什么问题,是的,我还添加了写入外部存储权限。它给了我文件未找到异常,
try
{
String path = Environment.getExternalStorageDirectory()+"/Hello/";
File file = new File(path+"hello.pdf");
System.out.println(file.toString());
if(!file.exists()){
file.getParentFile().mkdirs();
try {
file.createNewFile();
}
catch (IOException e)
{
// TODO Auto-generated catch block e.printStackTrace(); }
}
}
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(Environment.getExternalStorageDirectory()
+File.separator
+"Hello" //folder name
+File.separator
+"hello.pdf"));
document.open();
document.add(new Paragraph("hello"));
document.close();