TP6 arbres
This commit is contained in:
8
DEV.3.2/TP/TP7-Arbres/1.Repertoires/Main.java
Normal file
8
DEV.3.2/TP/TP7-Arbres/1.Repertoires/Main.java
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
16
DEV.3.2/TP/TP7-Arbres/1.Repertoires/Noeud.java
Normal file
16
DEV.3.2/TP/TP7-Arbres/1.Repertoires/Noeud.java
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
public class Noeud {
|
||||||
|
|
||||||
|
private ArrayList<Noeud> fils;
|
||||||
|
private File noeud;
|
||||||
|
|
||||||
|
public Noeud(File noeud) {
|
||||||
|
this.fils = null;
|
||||||
|
this.noeud = noeud;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Par polymorphisme et redéfinition on prend la valeur et les fils
|
||||||
|
public Noeud(ArrayList<Noeud> fils, File noeud) {
|
||||||
|
this.fils = fils;
|
||||||
|
this.noeud = noeud;
|
||||||
|
}
|
||||||
|
}
|
||||||
43
DEV.3.2/TP/TP7-Arbres/1.Repertoires/Repertoires.java
Normal file
43
DEV.3.2/TP/TP7-Arbres/1.Repertoires/Repertoires.java
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class Repertoires {
|
||||||
|
|
||||||
|
private File val;
|
||||||
|
private Noeud son;
|
||||||
|
|
||||||
|
public Repertoires(File root) {
|
||||||
|
try {
|
||||||
|
if(!root.isDirectory()) {
|
||||||
|
this.val = root;
|
||||||
|
} else {
|
||||||
|
this.son = new Noeud();
|
||||||
|
this.val = root;
|
||||||
|
try {
|
||||||
|
for(File files : root.listFiles()) {
|
||||||
|
this.son.add(new Repertoires(files));
|
||||||
|
}
|
||||||
|
}catch(SecurityException e2) {
|
||||||
|
System.err.println("access to read the directory was denied : "+e2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(SecurityException e1) {
|
||||||
|
System.err.println("the file you gave is not a directory : "+e1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
public void fileToString() {
|
||||||
|
String stringFile = "";
|
||||||
|
|
||||||
|
for(int i = 0; i != file.getName().length(); i++) {
|
||||||
|
stringFile = ""+file.getPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
return stringFile;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Repertoires file = new Repertoires(new File(args[0]));
|
||||||
|
}
|
||||||
|
}
|
||||||
0
DEV.3.2/TP/TP7-Arbres/1.Repertoires/toto/fichier4
Normal file
0
DEV.3.2/TP/TP7-Arbres/1.Repertoires/toto/fichier4
Normal file
Reference in New Issue
Block a user