Reputation: 524
How to edit and save uac protected files especially the hosts file (DNS mapping) through bat file / java.
Java throws IO exception. Because the file is not writable. Set write also fails.
File file = new File("C:\\Windows\\System32\\drivers\\etc\\hosts");
file.setWritable(true);
FileUtils.writeStringToFile(file, "127.0.0.1 test.com", true);
Exception File 'C:\Windows\System32\drivers\etc\hosts' cannot be written to
Upvotes: 0
Views: 125
Reputation: 1042
You have to give write permission default host file has read and execute permission only
Upvotes: 1