java - ListOfFiles, getPath, shuffling when have more than 3 -


im using display image in folder , subfolder, "works fine", files named in form ex:

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

the .xxx extension (a renamed tiff)

the program works in way:

you type number want, example: want 17000, type 17000, , return first .001 in screen, , others .002, .003 , how many have, want walk throught next image button , previsoly image...

the problem is: when try search number have more 4 .004 or more, dont display first, display "random", .002, 004 or other cant understand why, piece of code "path" it!! dont kill me because 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 busca");             } else {         //  joptionpane.showmessagedialog(null, diretorio);             (int = 0; < listoffiles.length; i++) {                    string matsonome[] = listoffiles[i].getname().split("\\.");                  (int i2 = 0; i2 < matsonome.length; i2 = i2 +2) {                      if(matsonome[i2].matches(matricula)) {                         system.out.println(matsonome[i2] = "." + matsonome[i2+1]); ... rest of code, if typed number image exist in folder 

i dit string matsonome check if first part of array matches typed number,.. i2 +2, coz wwhen split example 17000.001 , 17000.002

will in way:

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

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

will display correct cuz have less 4

17000.001 17000.002

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

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

why???

sorry bad english :(

i believe it's because order isn't guaranteed (if correctly understand question).

see documentation:

there no guarantee name strings in resulting array appear in specific order; not, in particular, guaranteed appear in alphabetical order.

that means you'll have sort array using static function.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -