如何授予对Intellij-Idea的访问权限来写入文件?



我正在尝试使用IntelliJ IDEA将文件写入我的Windows 7计算机。我正在使用文件和文件编写器程序来执行此操作。但是我收到一条错误消息,声称无法访问我的文件夹以执行此操作。

我尝试查看其他教程和有类似问题的人,但到目前为止我还没有看到任何有这个问题的人。我还查看了 IntelliJ 在防火墙中的权限,它们都在检查中。我还尝试使用不同的 derect,例如我的 SRC 文件夹和其他文件夹,但没有占上风。


public class Main {
public static void main(String[] args) throws IOException {
//fori loop
for(int a=0;a<1000;a++) { 
//writing to desktop
File file = new File("C:\Users\BlahBlah\Desktop\");
FileWriter fw = new FileWriter(file);
fw.write("Hey you!");
fw.close();
}
}
}

我应该期望将 1000 个文件流出到我的 PC 上,但我收到一个错误,告诉我"访问被拒绝"。下面列出了整个错误。

线程"main"中的异常 java.io.FileNotFoundException: C:\Users\BlahBlah\Desktop (Access is dedened(

例外很明显,它告诉您那里没有文件。事实上,C:\Users\BlahBlah\Desktop不是一个文件路径,你应该有这样的东西:

file = new File("C:\Users\BlahBlah\Desktop\test.txt");

而且您正在创建 1000 次文件,我认为您可能在那里也有错误。

尝试将索引值添加到文件名中,扩展名为 desktop1.txt

for(int a=0; a<1000;a++)
{
FileWriter fw=new FileWriter("D:\ desktop"+a+".txt");
fw.write("hey file."+a);
fw.close();
}   

最新更新