gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 18:35:47 25 4
gpt4 key购买 nike

我有如下 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com