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
| import java.io.*;
import java.util.*;
public class ListingMp3 extends Thread implements Runnable {
public static Vector<File> vect = new Vector<File>();
public ListingMp3(File Finit) {
this.Finit = Finit;
System.out.println("fichier initiale :" + Finit.getName());
}
@Override
public void run() {
ArrayList<File> array = new ArrayList<File>();
File[] listing = Finit.listFiles();
for (int i = 0; i < listing.length; i++) {
array.add(listing[i]);
}
for (int p = 0; p < array.size(); p++) {
list(array.get(p));
}
WriteFile(vect);
}
private void WriteFile(Vector<File> toWrite) {
try {
new File("mp3Listing.txt").delete();
PrintWriter out = new PrintWriter(new FileOutputStream(
"mp3Listing.txt", true));
for (int z = 0; z < toWrite.size(); z++) {
out.write(toWrite.elementAt(z) + "\n");
}
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
private void list(File file) {
if (file.isFile()) {
if (file.getName().endsWith(".mp3") || file.getName().endsWith(".wav")) {
System.out.println(file.getName());
vect.add(file);
}
} else if (file.isDirectory()) {
File[] listing = file.listFiles();
for (int i = 0; i < listing.length; i++) {
if (listing[i].isDirectory()) {
list(listing[i]);
} else {
if (listing[i].getName().endsWith(".mp3") || listing[i].getName().endsWith(".wav")) {
vect.add(listing[i]);
System.out.println(listing[i].getName());
}
}
}
}
}
public File Finit;
} |
Partager