[英]Fail to Write PDF In Emulator SDCard
我正在使用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();
File path = new File (Environment.getExternalStorageDirectory(),"Hello");
if (!path.exists()) {
path.mkdir();
}
File file = new File(path, "hello.pdf");
System.out.println(file.toString());
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(file);
document.open();
document.add(new Paragraph("hello");
document.close();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.