0

私はitextライブラリを使用しています.私はエミュレータSDカードにPDFを書き込むことができません. それは私に file not found 例外を与えます、

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();
4

1 に答える 1

1
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();
于 2013-06-02T09:14:02.610 に答える