java - 包含文件和目录的文件数组

标签 java arrays file storage

我有如下 Java 文件数组

File[] fileList = new File("c:/data").listFiles();

fileList 对象包含文件和目录。我想知道 fileList 对象中的项目的顺序(首先是文件,然后是目录,反之亦然)。

fileList 对象内的项目顺序每次都保持不变还是取决于任何因素?

提前致谢。

最佳答案

如果您查看docs ,它清楚地解释了:

Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname. If this abstract pathname does not denote a directory, then this method returns null. Otherwise an array of File objects is returned, one for each file or directory in the directory. Pathnames denoting the directory itself and the directory's parent directory are not included in the result. Each resulting abstract pathname is constructed from this abstract pathname using the File(File, String) constructor. Therefore if this pathname is absolute then each resulting pathname is absolute; if this pathname is relative then each resulting pathname will be relative to the same directory.

There is no guarantee that the name strings in the resulting array will appear in any specific order; they are not, in particular, guaranteed to appear in alphabetical order.

关于java - 包含文件和目录的文件数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22087436/

相关文章:

java - JFreeChart时间序列图表设置域区间

arrays - 功能方法 : Merge Two Arrays and Return a Tuple with common objects

javascript - 查找是否在文件输入上单击了 'cancel'

file - 从 Common Lisp 中的文本文件中读取序列

JavaAgent“java.lang.NoClassDefFoundError : de. bea.domingo.DNotesFactory

java - 在 Matlab 中编写 XML : How to add reference to DTD?

java - 如何在 onClick 事件触发时更改 Fragment?

c++ - 在 C++ 中对字符串使用 OR 运算符

python - 在创建二维数组/列表时遇到问题

django - Django 是否关闭并删除 TemporaryUploadedFiles 和 InMemoryUploadedFiles?