gpt4 book ai didi

java - ListOfFiles、getPath、超过 3 个时进行混排

转载 作者:行者123 更新时间:2023-11-30 04:15:52 25 4
gpt4 key购买 nike

我使用它来显示某个文件夹和子文件夹中的图像,一切“工作正常”,文件以此形式命名,例如:

17000.00117000.00218555.00118542.0011.0011.0021.0031.004......

.xxx 是扩展名(重命名为 TIFF)

程序的工作方式是这样的:

您输入您想要的数字,例如:我想要 17000,我输入 17000,它会在屏幕上返回第一个 .001,其他 .002、.003 以及它有多少个,我想步行通过下一个图像按钮和预先图像来完成它...

问题是:当我尝试搜索超过 4 .004 或更多的数字时,它不显示第一个,它显示“随机”、.002、004 或其他我无法理解为什么,这是我得到它的“路径”的代码!!不要杀我,因为代码^^!

...

        public void geraListaArquivos(String subdir, String matricula) {


String diretorio = "F:\\registro_sql\\Imagens\\Livro02" + "\\"

+ subdir + "\\";
String novaimagem = null;

File folder = new File(diretorio);
listOfFiles = folder.listFiles();
if (!folder.exists()) {
JOptionPane.showMessageDialog(null,"Não existe o diretório em que está tentando fazer a busca");
} else {
// JOptionPane.showMessageDialog(null, diretorio);
for (int i = 0; i < listOfFiles.length; i++) {

String matsonome[] = listOfFiles[i].getName().split("\\.");

for (int i2 = 0; i2 < matsonome.length; i2 = i2 +2) {

if(matsonome[i2].matches(matricula)) {
System.out.println(matsonome[i2] = "." + matsonome[i2+1]);
... the rest of the code, if the typed number image exist in the folder

我编辑了 String matsonome 以检查数组的第一部分是否与键入的数字匹配,.. i2 +2,因为它拆分时,例如 17000.001 和 17000.002

将是这样的:

matsonome[0] = 17000
matsonome[1] = 001
matsonome[2] = 17000
matsonome[3] = 002

在本例中,“System.out.println(matsonome[i2] = "."+ matsonome[i2+1]);”

将显示正确的,因为它少于 4

17000.00117000.002

但是如果输入的数字有4个或更多,则以这种方式显示(乱序):

xxxx.002xxxx.001xxxx.004xxxx.003

为什么???

抱歉英语不好:(

最佳答案

我相信这是因为订单无法保证(如果我正确理解了问题)。

请参阅documentation:

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.

这意味着您必须使用 static function. 对数组进行排序

关于java - ListOfFiles、getPath、超过 3 个时进行混排,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18409505/

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