1
我创建简单的对象序列化,并创建BufferedOutputStream正在引发异常AccessDeniedException。下面是代码:为什么AccessDeniedException在使用刚刚创建的文件夹时引发?
Path filePath = Paths.get("c:\\temp\\");
File xmlFile = new File("c:\\temp\\");
boolean success = xmlFile.mkdirs();
if (!success && ! xmlFile.exists()) {
// Directory creation failed
System.out.println("Failed to create a file: " + filePath);
}
try (
ObjectOutputStream objectOut = new ObjectOutputStream(
new BufferedOutputStream(Files.newOutputStream(filePath, StandardOpenOption.WRITE)))){
// Write three objects to the fi le
objectOut.writeObject(solarSystem); // Write object
System.out.println("Serialized: " + solarSystem);
} catch(IOException e) {
e.printStackTrace();
}
但目录是空的,如果没有不存在的话,它的创建...
什么是'filePath'?我没有看到声明和价值?请注意,你应该写入一个文件,而不是目录 - 以防万一'filePath'实际上是'“C:\\ temp”'。还要注意名称'xmlFile'表明你有一个文件,但它指向一个目录。 – Thomas 2012-01-30 14:56:32
你是对的。更新 – Eugene 2012-01-30 14:59:21
什么是'路径'? 'filePath'的实际值是多少? – Thomas 2012-01-30 15:01:30