为什么这段代码在 Windows 上失效了?
我正在尝试将一些代码从 Linux 移植到 Windows。我对 Windows 真的不太了解,所以我有点盲目。有问题的代码尝试使用 org.apache.commons.io.FileUtils 删除某些目录
// If the mergesegs worked, delete the segment dirs
for (File file : segments.listFiles())
{
if (!file.equals(mergedSegFile))
{
LOG.debug("deleting segment dir " + file);
FileUtils.deleteDirectory(file);
}
}
segments
是一个文件,mergedSegFile
也是一个文件。它因 IOException “无法删除文件:c:\www\tomcat\crawls\test\TestingCode.site\crawldir\segments\20101128194700\parse_test\part-00000\data”而终止。
这些文件是由先前运行的同一程序(执行一些 Nutch 爬行)创建的。在 cygwin 下执行 ls -l
显示用户和组是正确的,但权限为 000。
更多信息:
dir
没有告诉我任何有关权限的信息。- 我可以在 cmd.exe 窗口上使用
del
或在 cygwin bash 窗口上使用rm -rf
删除目录。 - 有问题的文件及其所在的目录是在同一程序的同一次运行中早期创建的。
- 计算机运行的是 Windows 7,所以我认为这意味着它是 NTFS。
I'm trying to port some code from Linux to Windows. I really don't know much about Windows, and so I'm kind of flying blind. The code in question attempts to delete some directories using org.apache.commons.io.FileUtils
// If the mergesegs worked, delete the segment dirs
for (File file : segments.listFiles())
{
if (!file.equals(mergedSegFile))
{
LOG.debug("deleting segment dir " + file);
FileUtils.deleteDirectory(file);
}
}
segments
is a File, as is mergedSegFile
. It dies with an IOException "Unable to delete file: c:\www\tomcat\crawls\test\TestingCode.site\crawldir\segments\20101128194700\parse_test\part-00000\data"
.
These files were created by a previous run of the same program (which does some Nutch crawling). Doing an ls -l
under cygwin shows the user and group are correct, but the perms are 000.
Further info:
dir
doesn't tell me anything about permissions.- I can remove the directory with
del
on a cmd.exe window orrm -rf
on a cygwin bash window. - The files in question, and the directory they are in, were created earlier in the same run of the same program.
- The computer is running Windows 7, so I assume that means it's NTFS.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里有很多可能性。这条路本身看起来并不糟糕。最好的办法是尝试从命令提示符手动删除该目录,然后查看出现的错误。
要检查的事项:
dir
,而不是ls
)。Plenty of possibilities here. The path itself doesn't look bad. Your best bet is to try to delete that directory manually from a command prompt and see what error you get.
Things to check:
dir
, notls
).