java.nio.Files.move()-OS X上的DirectoryNotEmptyException [英] java.nio.Files.move() - DirectoryNotEmptyException on OS X

查看:416
本文介绍了java.nio.Files.move()-OS X上的DirectoryNotEmptyException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个第三方库,其部分操作是将一个zip文件下载到一个temp目录中,将其解压缩,然后将其从temp目录中移到最终目录中……出于某种原因,这将系统属性保留为默认值时失败:

I'm running a 3rd party library, and part of its operation is to download a zip file to a temp directory, unzip it and then move it from the temp directory to a final directory... for some reason, this fails when I leave system properties to the default:

java.nio.file.DirectoryNotEmptyException: /var/folders/j_/1v53z7q15v51wyb00jzht_ch0000gn/T/vertx-68e24a9e-ee15-4b49-a796-7176714865ec
   at sun.nio.fs.UnixCopyFile.move(UnixCopyFile.java:491)
   at sun.nio.fs.UnixFileSystemProvider.move(UnixFileSystemProvider.java:261)
   at java.nio.file.Files.move(Files.java:1345)
   ...

但是,如果我将java.io.tmpdir设置为.tmp(并在我的工作目录中创建一个.tmp目录),它将起作用!

However if I set java.io.tmpdir to .tmp (and create a .tmp directory in my working dir), it works!

如果我使用sudo,这也不起作用.

This also does not work if I use sudo.

这真的让我很生气……要在OS X上运行该功能我需要怎么做?

This is really pissing me off... what do I need to do to get this working on OS X?

> java -version
  java version "1.7.0_17"
  Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
  Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

> uname -a
  Darwin daryl-teos-macbook-pro.fritz.box 12.2.0 Darwin Kernel Version 12.2.0: Sat Aug 25 00:48:52 PDT 2012; root:xnu-2050.18.24~1/RELEASE_X86_64 x86_64

关于, 达里尔

推荐答案

Given the following from the Java API Docs for Files.move:

当调用它来移动不为空的目录时,如果不需要移动目录中的条目,那么将移动该目录.例如,重命名同一FileStore上的目录通常将不需要移动目录中的条目.当移动目录要求移动其条目时,此方法将失败(通过抛出IOException).移动文件树可能涉及复制而不是移动目录,这可以通过使用copy方法与Files.walkFileTree实用工具方法一起完成.

When invoked to move a directory that is not empty then the directory is moved if it does not require moving the entries in the directory. For example, renaming a directory on the same FileStore will usually not require moving the entries in the directory. When moving a directory requires that its entries be moved then this method fails (by throwing an IOException). To move a file tree may involve copying rather than moving directories and this can be done using the copy method in conjunction with the Files.walkFileTree utility method.

这意味着该功能并非旨在跨网络或其他FileStore移动文件.当您更改tmp位置时,它会为您工作,因为在这种情况下,它只是在进行重命名而不是实际移动.

This implies that this function was not designed to move files across networks or different FileStores. It works for you when you change the tmp location because in that case it is simply doing a rename and not a physical move.

您没有提到如何选择最终目录",但是如果它是用户控制的,则好像必须是本地位置.

You did not mention how the 'final directory' is selected but if it is user controlled it seems as if it would have to be a local location.

这篇关于java.nio.Files.move()-OS X上的DirectoryNotEmptyException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆