我有以下與iText庫正確集成的代碼。FileOutputStream訪問被拒絕:JAVA
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();
}
}
此代碼返回錯誤消息,如下所示。
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)
然而,我是計算機管理員,我通常擁有所有的權限帳戶。我不明白他爲什麼讓我退縮Access is denied
。
該目錄是否存在? – pitseeker
您是否嘗試從用戶空間以外的某處訪問文件?或不同的驅動器? – sakura
是的,該目錄存在,該文件夾擁有傻瓜權限 – mortiped