1

im using this to display a image in a certain folder and subfolder, everything "works fine", the files are named in this form ex:

17000.001 17000.002 18555.001 18542.001 1.001 1.002 1.003 1.004 .....

the .xxx is the extension (a renamed TIFF)

the program works in this way:

You Type the Number you want, example: i want the 17000, i type 17000, and it return the FIRST .001 in the screen, and the others .002, .003 and how many it have, i want to walk throught it by a next image button and previsoly image...

the problem is: when i try to search for a number that have more than 4 .004 or more, it dont display the first, it display "random", .002, 004 or other i cant understand why, this is the piece of the code where i get the "path" to it!! dont kill me because the code ^^!

....

        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

i dit the String matsonome to check if the first part of the array matches the typed number,.. i2 +2, coz wwhen it split for example 17000.001 and 17000.002

will be in this way:

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

in this case the "System.out.println(matsonome[i2] = "." + matsonome[i2+1]);"

will display correct cuz it have less than 4

17000.001 17000.002

but if the typed number have 4 or more, it display in this way(out of order):

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

why???

sorry the bad english :(

4

1 回答 1

2

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

请参阅文档:

无法保证结果数组中的名称字符串会以任何特定顺序出现;特别是,它们不能保证按字母顺序出现。

这意味着您必须使用静态函数对数组进行排序。

于 2013-08-23T18:31:26.603 回答