When I try to create a file in C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
, I get the following error:
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)
I would like to know why I am getting this error and how to work around it.
When I put quotes around the path as suggested below, I get the following error:
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)
Line 26 is:
BufferedWriter w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("\"C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\StartUp\\test.bat\""), "utf-8"));