问题描述
我需要创建一个Java util,它将通过Unix(和/或Linux)文件系统递归,并建立目录结构的对象模型,检索文件信息-大小,创建日期,上次访问日期等-以及我需要在文件所在的物理存储设备上检索信息.理想情况下,此实用程序将是可移植的.我没有Java标准库的经验,只有Unix OS的经验有限.
I need to create a Java util that will recurse its way through a Unix (and/or Linux) filesystem and build an object model of the directory structure, retrieve file info - size, created date, last accessed date etc - plus I need to retrieve info on the physical storage device the files are sitting on. Ideally, this util will be portable. I have no experience of the Java standard libraries and only limited experience of Unix OS.
是否存在可以处理Unix文件系统的Java标准库?还是我将不得不通过某些API进行本地调用,然后担心可移植性?我有什么选择?
Are there Java standard libraries that will handle working with the Unix filesystem? Or am I going to have to make native calls through some API and then worry about portability? What options do I have?
推荐答案
查看 Apache Commons IO 和 FileUtils.iterator()特别是.这样您就可以浏览文件系统.主要是由于潜在的内存问题,使用迭代器比构建大量候选文件要好.
Check out Apache Commons IO and FileUtils.iterator() in particular. That'll allow you to navigate the file system. Using an iterator is better than building up a huge list of candidate files mainly because of the potential memory issues.
如果您需要对符号链接的特定访问权限,那么这可能还不够,您可能想查看JDK 7的早期版本.我知道Java 7的文件系统将具有围绕符号链接的一些功能.
If you need particular access to symlinks, then this may not be enough, and you may want to check out an early release of JDK 7. I understand the file system with Java 7 will have some capabilities surrounding symlinks.
注意:许多Unix文件系统都会给您ctime
,这是 inode 的创建日期,而不是文件的创建日期.
Note: many Unix filesystems will give you ctime
, which is the inode creation date and not the file creation date.
这篇关于用Java走Linux/Unix文件系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!