siegmann lib创建epub文件不起作用

时间:2014-09-15 19:05:51

标签: android epub

我从http://www.siegmann.nl/epublib/android下载了两个罐子 但示例代码不会创建文件 在我的SD卡或内部存储空间

    import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import nl.siegmann.epublib.domain.Author;
import nl.siegmann.epublib.domain.Book;
import nl.siegmann.epublib.epub.EpubWriter;
import android.app.Activity;
import android.os.Bundle;



public class EpubAppActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Book b =  new Book();
        b.getMetadata().addTitle("test epub book");
        b.getMetadata().addAuthor(new Author("author name"));

       EpubWriter w = new EpubWriter();

        FileOutputStream fos;
        try {

            File file = new File(getApplicationContext().getExternalFilesDir(null), "test.epub");
            if(!file.exists()){
                file.createNewFile();
            }
            fos = new FileOutputStream(file);
            w.write(b, fos);
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


    }
}

没有得到错误但我找不到文件(它没有创建)

1 个答案:

答案 0 :(得分:0)

我忘了添加

<uses-permission android: name = "android.permission.WRITE_EXTERNAL_STORAGE" />
Android Manifest中的