我不能用java访问windows的主机文件(只写):
java.io.FileNotFoundException: C:\Windows\system32\drivers\etc\hosts (Access is denied)
at java.io.FileOutputStream.open(Native Method)当我想要将我的文本附加到主机文件中时,出现上述错误...
这是我的代码:
BufferedWriter bw = null;
try {
// APPEND MODE SET HERE
bw = new BufferedWriter(new FileWriter(file,true));
bw.write(text);
bw.newLine();
bw.flush();
} catch(FileNotFoundException e) {
e.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally { try {
// always close the file
bw.close();
} catch (IOException ex) {
Logger.getLogger(FileWrite.class.getName()).log(Level.SEVERE, null, ex);
}
}
} // end test()此代码适用于windows其他位置的简单文件。(只需在c:\windows\上获取错误...
和:我使用microsoft清单来设置管理访问不起作用
设置对主机文件的完全访问权限不起作用
请帮帮我..
tnx
发布于 2016-02-08 20:53:20
检查您的java是否真的是以管理员身份运行的(例如,写入同一文件夹中的新文件)。显然存在访问问题,要解决这个问题,你需要了解你是谁(你的应用程序的用户/服务),以及你试图访问的资源(文件)的权限是什么。
这里有两种方法可以尝试和调试它: 1)你没有写文件的权限(你能读它吗?) 2)你没有进入文件夹的权限(你能列出其中的文件)
https://stackoverflow.com/questions/35269925
复制相似问题