用Javareplace主机文件

所以这里是我的代码,是的,我知道这是非常基本的。 但是我想完成的是replace位于System32 \ drivers \ etc文件夹中的主机文件,我这样做的问题是我得到一个访问被拒绝的错误。 我如何让程序访问在Windows文件夹中进行更改,类SaveURL也只是下载文件,并使用两个string通过函数saveImage传递名称和下载位置。 我怎样才能让自己进入? 在此先感谢,我真的很感激它。

private void jButton7MouseClicked(java.awt.event.MouseEvent evt) { String destinationHosts = "hosts"; String urlHosts = "https://dl.dropbox.com/s/awdvoprxyo7r2q6/hosts?dl=1"; Object hostOptions[] = {"Replace", "Close"}; File fileHosts = new File(destinationHosts); File dirHost = new File("hosts"); boolean dirHosts = dirHost.mkdir(); try { Runtime.getRuntime().exec("notepad.exe \\Windows\\system32\\drivers\\etc\\hosts"); jTextArea2.append("Opening Host File \n"); int hostFile = JOptionPane.showOptionDialog(rootPane, "Would you like to replace the Hosts File?", "Yes or No", JOptionPane.YES_NO_OPTION, JOptionPane.NO_OPTION, null, hostOptions, hostOptions[0]); if (hostFile == JOptionPane.YES_NO_OPTION) { jTextArea2.append("Downloading New Host File"); SaveUrl.saveImage(urlHosts, destinationHosts); fileHosts.renameTo(new File(dirHost, fileHosts.getName())); Path source = Paths.get("\\hosts\\hosts"); Path target = Paths.get("\\Windows\\system32\\drivers\\etc\\"); Files.copy(source, target); jTextArea2.append("Host file replaced"); } } catch (IOException ex) { Logger.getLogger(ToolKit1.class.getName()).log(Level.SEVERE, null, ex); } } 

Solutions Collecting From Web of "用Javareplace主机文件"