how to solve read only file system error in androi

2019-09-19 05:38发布

问题:

I am developing a program in which i must create pdf file inside application.

This is the code that i use for creating pdf file but an error occurred that say

"/Image.pdf:open failed:EROFS(read-only file system)"

This is my button click code:

Document document = new Document();
PdfWriter.getInstance(document,new FileOutputStream("Image.pdf"));
document.open();
Image image1 = Image.getInstance("watermark.png");
document.add(image1);
String imageUrl = "http://jenkov.com/images/20081123-20081123-3E1W7902-small-portrait.jpg";
Image image2 = Image.getInstance(new URL(imageUrl));
document.add(image2);
document.close();

回答1:

Try to write pdf in sdcard root directory:

PdfWriter.getInstance(document,new FileOutputStream(Environment.getExternalStorageDirectory().getAbsolutePath()+"Image.pdf"));


回答2:

first i thank Haresh Chhelana for his answers.

by using this code i can create new pdf file with an image in it.

Document document = new Document();
            PdfWriter.getInstance(document,new FileOutputStream(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Image.pdf"));
            document.open();
            Image image1 = Image.getInstance(Environment.getExternalStorageDirectory()+"/01.jpg");
            document.add(image1);
            document.close();