Fileoutputstream access denied: Java
•
Java
I have the following code correctly integrated with iText library
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 an error message, as shown below
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)
However, I am a computer administrator, and I usually have all the rights accounts I don't understand why he withdrew my visit and was refused
Solution
You are trying to access the directory The parameter of fileoutputstream should be the file / path object pointing to the file:
FileOutputStream file = new FileOutputStream("path/file.txt"); File -------------------------------^
For more information, see http://docs.oracle.com/javase/7/docs/api/java/io/FileOutputStream.html
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码