Liste chainee recursive
Fermé
wolwf59
Messages postés
2
Date d'inscription
jeudi 5 novembre 2015
Statut
Membre
Dernière intervention
6 novembre 2015
-
5 nov. 2015 à 15:49
wolwf59 Messages postés 2 Date d'inscription jeudi 5 novembre 2015 Statut Membre Dernière intervention 6 novembre 2015 - 6 nov. 2015 à 08:45
wolwf59 Messages postés 2 Date d'inscription jeudi 5 novembre 2015 Statut Membre Dernière intervention 6 novembre 2015 - 6 nov. 2015 à 08:45
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
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
A voir également:
- Liste chainee recursive
- Liste déroulante excel - Guide
- Liste déroulante en cascade - Guide
- Liste site streaming illégal - Accueil - Services en ligne
- Liste code ascii - Guide
- Liste groupe whatsapp - Guide
2 réponses
KX
Messages postés
16760
Date d'inscription
samedi 31 mai 2008
Statut
Modérateur
Dernière intervention
12 février 2025
3 020
5 nov. 2015 à 19:42
5 nov. 2015 à 19:42
Bonjour,
Je ne suis pas sûr que ton titre soit bien changé, ou alors je ne vois pas le rapport avec une liste chaînée.
Pour manipuler des fichiers tu as la classe File, voir sa documentation :
https://docs.oracle.com/javase/8/docs/api/index.html?java/io/File.html
Les méthodes qui vont t'intéresser c'est isDirectory() et listFiles().
Je ne suis pas sûr que ton titre soit bien changé, ou alors je ne vois pas le rapport avec une liste chaînée.
Pour manipuler des fichiers tu as la classe File, voir sa documentation :
https://docs.oracle.com/javase/8/docs/api/index.html?java/io/File.html
Les méthodes qui vont t'intéresser c'est isDirectory() et listFiles().
wolwf59
Messages postés
2
Date d'inscription
jeudi 5 novembre 2015
Statut
Membre
Dernière intervention
6 novembre 2015
6 nov. 2015 à 08:45
6 nov. 2015 à 08:45
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();
}
}
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();
}
}