IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

avec Java Discussion :

Hello probleme de boucle, je ne comprends pas


Sujet :

avec Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Inscrit en
    Janvier 2014
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Japon

    Informations forums :
    Inscription : Janvier 2014
    Messages : 18
    Par défaut Hello probleme de boucle, je ne comprends pas
    je suis un peu en panique,
    je dois utiliser ce petit prog pour passer dans beaucoup de dossiers,
    je n'ai pas de probleme dans le prog écrit sans la boucle


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
     
     
    public static void  checkIfEnoughFilesfor1(String PathOriginFolder,String pathDestinationFolder, int selectParDossier) throws IOException {
     
            String Lepatha = PathOriginFolder;
            String Lepath2a =  pathDestinationFolder;
            System.out.println("le dossier d'origine: "+ Lepatha);
            System.out.println("le dossier de destination: "+ Lepath2a);
     
     
            File dir = new File(Lepath2a);
            File dirOrig = new File(Lepatha);
     
     
     
            int nbrSelecionesa = selectParDossier;
     
            System.out.println("nombre de photos necessaires: "+ nbrSelecionesa);
     
            String[] files = dir.list();
            String[] filesOrig = dirOrig.list();
     
            System.out.println( "Nombres d'images dans le dossier MEO: "+files.length);
     
     
            List<Integer> hazardNumbers = new ArrayList<>();
     
            int nbrrestant= nbrSelecionesa-files.length;
            System.out.println("le nombre de files necessaire est "+nbrrestant);
            for(int iab=0; iab<nbrrestant;){
                int idz=(int)(Math.random()*filesOrig.length);
                //System.out.println(idz);
                if (filesOrig[idz].endsWith(".JPG")) {
                    if (!hazardNumbers.contains(idz)) {
                        hazardNumbers.add(idz);
                    }
                }
                iab++;
            }
     
            System.out.println("les photos choisies au Hasard: "+ hazardNumbers);
     
            Desktop.getDesktop().open(dir);
            Desktop.getDesktop().open(dirOrig);
     
     
            for (int i = 0; i < nbrrestant;i++ ) {
                Path temp = Files.move (Paths.get(PathOriginFolder+"\\"+filesOrig[hazardNumbers.get(i)]),
                        Paths.get(pathDestinationFolder+"\\"+filesOrig[hazardNumbers.get(i)]));
            }
     
     
     
     
     
        }

    Donc j'ai mis une boucle et j'ai une exception

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
     
    public  void  checkIfEnoughFilesForM(String nomDossier3) throws Exception {
            String ND3=nomDossier3;
            Table t3 = CreateMDirectory(ND3);
            //System.out.println(t3.columnNames());
            t3.sortAscendingOn("Nom fichier");
            //System.out.println(t3);
            DoubleColumn nc = DoubleColumn.create("nombreDePhotos",t3.rowCount());
            t3.addColumns(nc);
            String input;
            double selectParDossier=0;
            for (int i = 0; i <2 ; i++) { //t3.rowCount()
            String Lepatha = t3.get(i, 1).toString();
            String Lepath2a =  t3.get(i, 3).toString();
            System.out.println("le dossier d'origine: "+ Lepatha);
            System.out.println("le dossier de destination: "+ Lepath2a);
            Scanner myObj = new Scanner(System.in);
            System.out.println("Entre le nombre necessaire de photos:");
            double nbrphnec = myObj.nextDouble();
            nc.set(i,nbrphnec);
     
            File dir = new File(Lepath2a);
            File dirOrig = new File(Lepatha);
            double nbrSelecionesa = nbrphnec;
            System.out.println("nombre de photos necessaires: "+ nbrSelecionesa);
            String[] files = dir.list();
            String[] filesOrig = dirOrig.list();
            System.out.println( "Nombres d'images dans le dossier MEO: "+files.length);
            List<Integer> hazardNumbers = new ArrayList<>();
            int nbrrestant= (int) (nbrSelecionesa-files.length);
            System.out.println("le nombre de files necessaire est "+nbrrestant);
            for(int iab=0; iab<nbrrestant;){
                int idz=(int)(Math.random()*filesOrig.length);
                    if (filesOrig[idz].endsWith(".JPG")) {
                        if (!hazardNumbers.contains(idz)) {
                            hazardNumbers.add(idz);
                        }
                    }
                    iab++;
                }
     
                System.out.println("les photos choisies au Hasard: "+ hazardNumbers);
     
                for (int i2 = 0; i2 < nbrrestant;i2++ ) {
                    Path temp = Files.move (Paths.get(Lepatha+"\\"+filesOrig[hazardNumbers.get(i)]),
                            Paths.get(Lepath2a+"\\"+filesOrig[hazardNumbers.get(i)]));
                    Desktop.getDesktop().open(dir);
                    Desktop.getDesktop().open(dirOrig);
                }
            }
        }
     
        public static void main (String[]args) throws Exception
        {
            Main client = new Main();
            //client.Create1Directory("G:\\Stock\\Arima\\","22. 渡部整形外科 MEO");
            //client.CreateMDirectory("G:\\Stock\\Ishibashi");
     
            client.checkIfEnoughFilesForM("G:\\\\Stock\\\\Ishibashi");
     
           // client.listDirectoryInFolder("G:\\Stock\\Kinoshita");
            //client.checkIfEnoughFilesfor1("G:\\Stock\\Arima\\22. 渡部整形外科 MEO","G:\\Stock\\Arima\\Selection 22. 渡部整形外科 MEO", 10);
     
        }
     
     
    }
    Le message d'erreur

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    Exception in thread "main" java.nio.file.NoSuchFileException: G:\Stock\Ishibashi\1. 
    MEO\IMG_5090.JPG
    	at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:85)
    	at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
    	at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
    	at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:326)
    	at java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:292)
    	at java.base/java.nio.file.Files.move(Files.java:1426)
    	at com.company.Main.checkIfEnoughFilesForM(Main.java:226)
    	at com.company.Main.main(Main.java:240)

    Je suis un peu perdu.

  2. #2
    Modérateur

    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    12 582
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 12 582
    Par défaut
    Hello,

    la boucle n'est pas la seule différence. A ta place j'accuserais le reste, pas la boucle.

    Mais bon, si tu veux qu'on regarde bien ce qui se passe, il faut montrer tout ton code, pas juste une partie. Il faut qu'on puisse l'essayer, et là on peut pas.
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  3. #3
    Membre averti
    Homme Profil pro
    Inscrit en
    Janvier 2014
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Japon

    Informations forums :
    Inscription : Janvier 2014
    Messages : 18
    Par défaut
    Citation Envoyé par thelvin Voir le message
    Hello,

    la boucle n'est pas la seule différence. A ta place j'accuserais le reste, pas la boucle.

    Mais bon, si tu veux qu'on regarde bien ce qui se passe, il faut montrer tout ton code, pas juste une partie. Il faut qu'on puisse l'essayer, et là on peut pas.
    Aucun soucis,
    J'ai juste un peu anonymisé, avec ma boite on sait jamais.

    Vous avez un disque dur externe qui contient un dossier par responsable, et dedans chaque client a son dossier.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
     
     
    package com.company;
     
    import tech.tablesaw.api.DoubleColumn;
    import tech.tablesaw.api.StringColumn;
    import tech.tablesaw.api.Table;
     
    import java.awt.*;
    import java.io.*;
    import java.io.File;
    import java.nio.file.*;
    import java.nio.file.Files;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Scanner;
     
     
    public class Main {
     
        public void Create1Directory(String Path33, String nomFile) throws Exception {
            //Pour creer un seul dossier
     
            File file = new File(Path33 + "Selection "+ nomFile);
            if (!file.exists()) {
                if (file.mkdir()) {
                    System.out.println("Directory is created!");
                } else {
                    System.out.println("Failed to create directory!");
                }
            }
        }
     
        public Table CreateMDirectory(String nomDossier2) throws Exception {
    //Pour creer plusieurs dossiers en se basant sur un Tableau
            String ND2 = nomDossier2;
            Table t2 = listDirectoryInFolder(ND2);
            for (int i = 0; i <t2.rowCount() ; i++) { //
               // System.out.println(t2.get(i, 0).toString()); //
                File file = new File(ND2 + "\\" + "Selection " + t2.get(i, 0).toString());
                if (file.exists()) {
                   // System.out.println("Directory exists already!"); //
                } else {
                    file.mkdir();
                   // System.out.println("Directory is created!"); //
                }
     
            }
            Table t3 = listDirectoryInFolder(ND2);
            return t3;
     
        }
     
        public Table listDirectoryInFolder(String nomDossier) throws Exception {
            String ND = nomDossier;
            File file = new File(ND);
            File[] listOfFiles = file.listFiles();
            Table t = Table.create();
            List<String> noma = new ArrayList<>();
            List<String> patha = new ArrayList<>();
            List<String> nomb = new ArrayList<>();
            List<String> pathb = new ArrayList<>();
            //Nombre de fichiers dans le dossier
            System.out.println("Nombres de Files/Directory dans le dossier: "+listOfFiles.length);
     
     
            for (int i = 0; i < listOfFiles.length; i++) {
                if (listOfFiles[i].isFile()) {
                    //System.out.println("File Name: " + listOfFiles[i].getName());
                    noma.add(listOfFiles[i].getName());
                    //System.out.println("File Path: " + listOfFiles[i].getAbsolutePath());
                    patha.add(listOfFiles[i].getAbsolutePath()); }
                else if (listOfFiles[i].isDirectory()) {
                    if (listOfFiles[i].getName().startsWith("Selection")){
                        //System.out.println("Directory Name: " + listOfFiles[i].getName());
                        nomb.add(listOfFiles[i].getName());
                        //System.out.println("Directory Path: " + listOfFiles[i].getAbsolutePath());
                        pathb.add(listOfFiles[i].getAbsolutePath());
                    }
                    else
                        {//System.out.println("Directory Name: " + listOfFiles[i].getName());
                            noma.add(listOfFiles[i].getName());
                    //System.out.println("Directory Path: " + listOfFiles[i].getAbsolutePath());
                    patha.add(listOfFiles[i].getAbsolutePath());}
     
     
                }
            }
     
            String[] nom2 = new String[noma.size()];
            String[] path2 = new String[patha.size()];
            String[] nom3 = new String[noma.size()];
            String[] path3 = new String[patha.size()];
     
            nom2 = noma.toArray(nom2);
            path2 = patha.toArray(path2);
            nom3 = nomb.toArray(nom3);
            path3 = pathb.toArray(path3);
     
            StringColumn column0 = StringColumn.create("Nom fichier", nom2 );
            StringColumn column1 = StringColumn.create("Path1", path2 );
            StringColumn column2 = StringColumn.create("Nom dossier selection", nom3 );
            StringColumn column3 = StringColumn.create("Path2", path3 );
     
            t.addColumns(column0);
            t.addColumns(column1);
            t.addColumns(column2);
            t.addColumns(column3);
     
     
     
            //System.out.println(t);
            t.write().csv("test.csv");
            return t;
            /*
            t.clear();
            noma.clear();
            patha.clear();
            column0.clear();
            column1.clear();
            nomb.clear();
            pathb.clear();
            column2.clear();
            column3.clear();
             */
     
     
        }
     
        public static void  checkIfEnoughFilesfor1(String PathOriginFolder,String pathDestinationFolder, int selectParDossier) throws IOException {
     
            String Lepatha = PathOriginFolder;
            String Lepath2a =  pathDestinationFolder;
            System.out.println("le dossier d'origine: "+ Lepatha);
            System.out.println("le dossier de destination: "+ Lepath2a);
     
     
            File dir = new File(Lepath2a);
            File dirOrig = new File(Lepatha);
     
     
     
            int nbrSelecionesa = selectParDossier;
     
            System.out.println("nombre de photos necessaires: "+ nbrSelecionesa);
     
            String[] files = dir.list();
            String[] filesOrig = dirOrig.list();
     
            System.out.println( "Nombres d'images dans le dossier MEO: "+files.length);
     
     
            List<Integer> hazardNumbers = new ArrayList<>();
     
            int nbrrestant= nbrSelecionesa-files.length;
            System.out.println("le nombre de files necessaire est "+nbrrestant);
            for(int iab=0; iab<nbrrestant;){
                int idz=(int)(Math.random()*filesOrig.length);
                //System.out.println(idz);
                if (filesOrig[idz].endsWith(".JPG")) {
                    if (!hazardNumbers.contains(idz)) {
                        hazardNumbers.add(idz);
                    }
                }
                iab++;
            }
     
            System.out.println("les photos choisies au Hasard: "+ hazardNumbers);
     
            Desktop.getDesktop().open(dir);
            Desktop.getDesktop().open(dirOrig);
     
     
            for (int i = 0; i < nbrrestant;i++ ) {
                Path temp = Files.move (Paths.get(PathOriginFolder+"\\"+filesOrig[hazardNumbers.get(i)]),
                        Paths.get(pathDestinationFolder+"\\"+filesOrig[hazardNumbers.get(i)]));
            }
     
     
     
     
     
        }
     
        public  void  checkIfEnoughFilesForM(String nomDossier3) throws Exception {
            String ND3=nomDossier3;
            Table t3 = CreateMDirectory(ND3);
            //System.out.println(t3.columnNames());
            t3.sortAscendingOn("Nom fichier");
            //System.out.println(t3);
            DoubleColumn nc = DoubleColumn.create("nombreDePhotos",t3.rowCount());
            t3.addColumns(nc);
            String input;
            double selectParDossier=0;
            for (int i = 13; i <t3.rowCount(); ) { //t3.rowCount()
            String Lepatha = t3.get(i, 1).toString();
            String Lepath2a =  t3.get(i, 3).toString();
            System.out.println("le dossier d'origine: "+ Lepatha);
            System.out.println("le dossier de destination: "+ Lepath2a);
            Scanner myObj = new Scanner(System.in);
            System.out.println("Entre le nombre necessaire de photos:");
            double nbrphnec = myObj.nextDouble();
            nc.set(i,nbrphnec);
            File dir = new File(Lepath2a);
            File dirOrig = new File(Lepatha);
            double nbrSelecionesa = nbrphnec;
            System.out.println("nombre de photos necessaires: "+ nbrSelecionesa);
            String[] files = dir.list();
            String[] filesOrig = dirOrig.list();
            System.out.println( "Nombres d'images dans le dossier MEO: "+files.length);
            List<Integer> hazardNumbers = new ArrayList<>();
            int nbrrestant= (int) (nbrSelecionesa-files.length);
            System.out.println("le nombre de files necessaire est "+nbrrestant);
            for(int iab=0; iab<nbrrestant;){
                int idz=(int)(Math.random()*filesOrig.length);
                    if (filesOrig[idz].endsWith(".JPG")) {
                        if (!hazardNumbers.contains(idz)) {
                            hazardNumbers.add(idz);
                        }
                    }
                iab++;
                }
     
                System.out.println("les photos choisies au Hasard: "+ hazardNumbers);
     
                for (int ia = 0; ia < nbrrestant;ia++ ) {
                   //System.out.println(Lepatha+"\\"+filesOrig[hazardNumbers.get(i)]);
                   System.out.println(Lepath2a+"\\"+filesOrig[hazardNumbers.get(i)]);
                   Path temp = Files.move (Paths.get(Lepatha+"\\"+filesOrig[hazardNumbers.get(i)]),
                            Paths.get(Lepath2a+"\\"+filesOrig[hazardNumbers.get(i)]));
                }
                Desktop.getDesktop().open(dir);
                Desktop.getDesktop().open(dirOrig);
                Scanner myObj3 = new Scanner(System.in);
                System.out.println("On augmente de combien la boucle?:");
                int boucleavance = myObj3.nextInt();
                i=i+boucleavance;
                System.out.println("Bon, maintenant i est egal a: "+i);
                //System.out.println(t3);
            }
     
        }
     
        public static void main (String[]args) throws Exception
        {
            Main client = new Main();
            //client.Create1Directory("G:\\Stock\\Arima\\","22 MEO");
            //client.CreateMDirectory("G:\\Stock\\Ishibashi");
            //client.listDirectoryInFolder("G:\\Stock\\Ishibashi");
            client.checkIfEnoughFilesForM("G:\\Stock\\Ishibashi");
     
     
            //client.checkIfEnoughFilesfor1("G:\\Stock\\Ishibashi\\19 MEO","G:\\Stock\\Ishibashi\\Selection 19", 10);
     
        }
     
     
    }

  4. #4
    Modérateur

    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    12 582
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 12 582
    Par défaut
    Et le code qui fait pas d'erreur ? Celui sans la boucle ?
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  5. #5
    Membre averti
    Homme Profil pro
    Inscrit en
    Janvier 2014
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Japon

    Informations forums :
    Inscription : Janvier 2014
    Messages : 18
    Par défaut
    Citation Envoyé par thelvin Voir le message
    Et le code qui fait pas d'erreur ? Celui sans la boucle ?
    pour checkIfEnoughFilesfor1(),
    en fait si il en fait des erreurs, indexout of bound, mais en relançant j'arrivais à ce que je voulais.
    C'est pour ça que l’incrémentation de la boucle pour
    checkIfEnoughFilesForM()
    est en dehors.
    Je me disais que je devrais refaire plusieurs fois des passages.

    En fait avec checkIfEnoughFilesForM() il y a le déplacement de la première image,
    et puis après ça bloque.
    Enfin ça c'était avant, je crois qu'il me faisais une autre erreur,
    là j'ai comme erreur:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    nombre de photos necessaires: 20.0
    Nombres d'images dans le dossier MEO: 7
    le nombre de files necessaire est 13
    les photos choisies au Hasard: [82, 25, 111, 123, 41, 68, 71, 39, 37, 33, 128, 81, 144]
    Exception in thread "main" java.lang.IndexOutOfBoundsException: Index 13 out of bounds for length 13
    	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
    	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
    	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
    	at java.base/java.util.Objects.checkIndex(Objects.java:373)
    	at java.base/java.util.ArrayList.get(ArrayList.java:426)
    	at com.company.Main.checkIfEnoughFilesForM(Main.java:226)
    	at com.company.Main.main(Main.java:248)
    J'ai même parfois des situation comme
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Exception in thread "main" java.lang.IndexOutOfBoundsException: Index 13 out of bounds for length 13
    En tout cas Merci thelvin!!!

  6. #6
    Membre averti
    Homme Profil pro
    Inscrit en
    Janvier 2014
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Japon

    Informations forums :
    Inscription : Janvier 2014
    Messages : 18
    Par défaut
    Donc j'ai réglé le problème avec ma boucle
    au lieu de for utiliser while...
    évident, mais pas venu à l'esprit.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
     int iab=0;
                while (iab<nbrrestant){
                int idz=(int)(Math.random()*filesOrig.length);
                    if (filesOrig[idz].endsWith(".JPG")) {
                        if (!hazardNumbers.contains(idz)) {
                            hazardNumbers.add(idz);
                        }
                    }
                iab++;
                }
    Edit: ça règle rien....
    mmmm
    Si quelqu'un a une solution????

    Sinon,
    J'ai compris l'erreur

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
     
     int ia = 0;
                while (ia<hazardNumbers.size()) {
                   System.out.println(Lepatha+"\\"+filesOrig[hazardNumbers.get(ia)]);
                   System.out.println(Lepath2a+"\\"+filesOrig[hazardNumbers.get(ia)]);
                   Path temp = Files.move (Paths.get(Lepatha+"\\"+filesOrig[hazardNumbers.get(ia)]),
                            Paths.get(Lepath2a+"\\"+filesOrig[hazardNumbers.get(ia)]));
                    ia++;
                }
    En remplaçant par un while je me suis aperçu que j'avais mis la variagble i et non ia....
    donc maintenant ça marche...
    Seul problème la boucle des chiffres du hasard.
    l’incrémentation n'est pas systématique,
    il faudrait que je trouve un moyen de toujours vérifier ....

    Voilà...
    d'ou l'importance de formuler les questions...
    l'importance des forums...
    ahhhh
    J'ai viré la variable externe,
    et avec while (hazardNumbers.size()<nbrrestant)
    tout marche comme sur des roulettes...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    while (hazardNumbers.size()<nbrrestant){
                int idz=(int)(Math.random()*filesOrig.length);
                    if (filesOrig[idz].endsWith(".JPG")) {
                        if (!hazardNumbers.contains(idz)) {
                            hazardNumbers.add(idz);
                        }
                    }
     
                }
    Prochain challenge, intégrer au tableau les nombres inséré à la main (nombre de photos sélectionnées) les exporter sur un csv et donner le choix 1) ouverture du csv 2)vérification du contenu du dossier.

    Content!

Discussions similaires

  1. Probleme de compilation, je ne comprends pas.
    Par Magnusmen dans le forum Unity
    Réponses: 2
    Dernier message: 30/09/2014, 11h38
  2. Problème de boucle (je ne comprend pas)
    Par Glorfindel555 dans le forum VB.NET
    Réponses: 5
    Dernier message: 16/01/2012, 21h14
  3. Probleme avec les get/ let de ma classe : je ne comprends pas l'erreur
    Par EvaristeGaloisBis dans le forum VB 6 et antérieur
    Réponses: 5
    Dernier message: 22/07/2007, 12h05
  4. Probleme de boucle (rigolez pas !)
    Par Slumpy dans le forum VB.NET
    Réponses: 9
    Dernier message: 12/06/2007, 14h19
  5. Boucle avec chaine vide : je comprends pas
    Par Zapan dans le forum Langage
    Réponses: 8
    Dernier message: 14/02/2007, 17h27

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo