I have the following code with the iText library properly integrated.
import java.io.*;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.PdfWriter;
@org.eclipse.jdt.annotation.NonNullByDefault(true)
public class HelloWorld {
public static final String RESULT = "C:\\Users\\administrator\\Pictures\\tuto";
@SuppressWarnings("resource")
public static void main(String[] args) throws DocumentException, IOException {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(RESULT));
document.open();
document.add(new Paragraph("Hello World!"));
document.close();
}
}
This code returns me an error message, which is as follows.
Exception in thread "main" java.io.FileNotFoundException: C:\Users\valentin.schaefer\Pictures\tuto (Access is denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at HelloWorld.main(HelloWorld.java:25)
Yet I am the computer administrator and I normally have all permissions account. I don't understand why he retourn me Access is denied
.
You are trying to access the directory. The parameter of the FileOutputStream should be a File
/ Path
object pointing to a file:
FileOutputStream file = new FileOutputStream("path/file.txt");
File -------------------------------^
For more detail take a look on http://docs.oracle.com/javase/7/docs/api/java/io/FileOutputStream.html
You need to have permission to access that file location. There are two possible solutions.
1. use deferent file location to store your file (eg: D:\\somewhere)
2. make sure that you have permission to access current location by granting
read write permissions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With