Liste chainee recursive
wolwf59
Messages postés
2
Statut
Membre
-
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
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 code ascii - Guide
- Liste déroulante en cascade - Guide
- Site dangereux liste - Guide
- Voir liste d'amis facebook - Guide
2 réponses
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().
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();
}
}