gpt4 book ai didi

java - 拒绝访问 - 无法在特定目录中创建文件

转载 作者:行者123 更新时间:2023-12-04 12:15:42 25 4
gpt4 key购买 nike

<分区>

当我尝试在 C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp 中创建文件时,出现以下错误:

java.io.FileNotFoundException: C:\ProgramData\Microsoft\Windows\Start Menu\Progr
ams\StartUp\test.bat (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 Program.testMethod(Program.java:26)
at Program.main(Program.java:14)

我想知道为什么会出现此错误以及如何解决它。

当我按照下面的建议在路径周围加上引号时,出现以下错误:

java.io.FileNotFoundException: "C:\ProgramData\Microsoft\Windows\Start Menu\Prog
rams\StartUp\test.bat" (The filename, directory name, or volume label syntax is i
ncorrect)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at Program.testMethod(Program.java:26)
at Program.main(Program.java:14)

第 26 行是:

BufferedWriter w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("\"C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\StartUp\\test.bat\""), "utf-8"));

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com