Liste chainee recursive

wolwf59 Messages postés 2 Statut Membre -  
wolwf59 Messages postés 2 Statut Membre -
Bonjour,
Je suis debutant en java et j'ai un petit cas d'algorithme;
Il s'agit de récupérer à partir d'un repertoire existant sur mon poste,la liste des sous repertoires et pour chaque sous repertoire afficher la liste des fichiers trouvés par nom dans une liste de manière recursive.
Merci

2 réponses

  1. wolwf59 Messages postés 2 Statut Membre
     
    Bonjour,
    Merci por ta reponse.
    Mais j'ai reussi à faire ca,par contre quand je lance la console je n'affiche qu'un seul fichier,j'arrive pas à afficher le contenu de mon repertoire.

    public static void main(String[] args) throws IOException {

    Path theDirectory = Paths.get("C:/FORMATION-CHARTEV2/ateliers");
    DirectoryStream<Path> stream = Files.newDirectoryStream(theDirectory);
    try {
    Iterator<Path> iterator = stream.iterator();
    while(iterator.hasNext()) {
    Path p = iterator.next();
    System.out.println(p);
    scanDir(theDirectory);
    }
    } finally {
    stream.close();
    }

    }

    public static void scanDir(Path theDirectory) throws IOException {

    System.out.println(theDirectory);

    if (!Files.isDirectory(theDirectory)) {
    System.out.println("1 :"+theDirectory);
    } else {
    System.out.println("2 :"+theDirectory);
    //trouver le bon parcours repertoire

    DirectoryStream<Path> stream = Files.newDirectoryStream(theDirectory);
    try {
    Iterator<Path> iterator = stream.iterator();
    while(iterator.hasNext()) {
    Path p = iterator.next();
    System.out.println(p);
    scanDir(theDirectory);
    }
    } finally {
    stream.close();
    }

    }
    0