java.io.File.list() giving different order as the folders created sequentially [duplicate]

StackOverflow https://stackoverflow.com/questions/21275228

  •  01-10-2022
  •  | 
  •  

문제

java.io.File.list() giving different order as the folders created sequentially

While creating the Temporary folders with name as

"Temp" + auto-incremented number 
e.g. Temp1, Temp2, Temp3...Temp10, Temp11 and so on. 

But when I use java.io.File.list() to get the folder list to further processing in order as the folder created,

but its giving as Temp1, Temp10, Temp11...Temp19, Temp2, Temp20, Temp21 and so on.

I also tried Arrays.sort(files); but no change in order of folder list

Please tell how to get the same order list as the folders created sequentially?

도움이 되었습니까?

해결책

It's because the way how java compares strings by default in java (lexicographic order). You can define your own comparator for File objects and sort.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top