文件在Java 1.5中工作,但在Java 7中不工作(Java.io.FileNotFoundException权限被拒绝)
我有一个文件正试图访问。当我在Java1.5中访问它时,一切正常。后来我升级到了Java 7,现在我得到了一个Java。伊奥。FileNotFoundException权限被拒绝错误
java.io.FileNotFoundException: /folder/test.xml (Permission denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:212)
at java.io.FileOutputStream.<init>(FileOutputStream.java:104)
at SerializeUtil.write(Unknown Source)
它实际上是在尝试使用XMLEncoder写入文件
XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(filename)));
encoder.writeObject(object);
encoder.close();
# 1 楼答案
如果您使用的是Unix/Linux,请在运行java的用户下尝试以下命令 $touch/文件夹/测试。xml
如果文件位于其他位置(例如/home/AAA/folder/test.xml),请替换上述路径
其目的是测试当前用户是否可以编写该文件