简体   繁体   English

为什么listFiles()不保证订单?

[英]Why does listFiles() not guarantee order?

This seems like a strange thing to say. 似乎是一件奇怪的事情。

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. 特别是,它们不保证按字母顺序出现。

Why can't the order be guaranteed? 为什么不能保证订单? What one gets when one ls could, for example be a reasonable default. 一个得到什么,当一个ls可能是,例如,一个合理的默认值。

Is this something that was decided for (performance?) reason, or perhaps where is some deeper truth out there? 这是因为(表现?)原因而决定的,或者可能是哪里有更深层次的真理?

As far as I know, there is no natural order that files gravitate toward. 据我所知,文件没有自然顺序。 If you say alphabetic, then with which locale/collating sequence? 如果你说字母,那么使用哪种语言环境/整理顺序? Do all OSes that java runs on support that order intrinsically? java运行的所有操作系统是否支持本地命令? If not, then the API would need to resort whatever was received from the OS. 如果没有,则API将需要诉诸从OS接收的任何内容。 Since it is likely that you the API client 1) may not care or 2) will want something different, it makes much more sense to just deliver the files with no guaranteed order rather than doing a wasted sort. 由于API客户端1)可能不关心或2)想要不同的东西,因此只提供没有保证订单的文件而不是浪费排序更有意义。 If you care, you can do the sort. 如果你在乎,你可以进行排序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM