Reputation: 31
Hi how can I get rid of C drive access with java codes I can do this with manual but I want to do this with java codes
here is my code
File file=new File("C:\\Windows\\b.txt");
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
System.out.println("file not created and");
e.getMessage();
e.printStackTrace();
}
And my exceptions
java.io.IOException: Access is denied
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:1006)
at tekrar.Write.main(Write.java:26)`
Upvotes: 2
Views: 4840
Reputation: 1088
you need to run the program as an administrator to edit the C:\Windows folder. this is a system folder that you should not access.
Upvotes: 3
Reputation: 5995
You cannot write anything in the system folder without administrator privileges in windows. As I understand you cannot request administrator access from within a Java program and you'll have to RUN the application in admin mode. See this question for some tips: Run Java file as Administrator with full privileges
P.S. Do you really need to write into the windows folder?
Upvotes: 0