Programmer un listeur de fichier
Sylbar
-
Hyperion -
Hyperion -
Bonjour tlm :) ,voila je suis en train de faire un prog qui va répertorié tous les fichier et dossier dans le répertoire selectionné. voici le code que jai
import java.io.*;
import javax.swing.JFileChooser;
import java.util.*;
class EssaiChoixFichier
{
static String indentation = new String();
public void listeur(File dir) {
process(dir);
if (dir.isDirectory()) {
String[] children = dir.list();
indentation += " ";
for (int i=0; i<children.length; i++) {
listeur(new File(dir, children[i]));
}
indentation = indentation.substring(0,indentation.length()-1);
}
}
public void process(File dir) {
try {
System.in.read();
System.in.read();
}
catch(IOException e){}
System.out.println(indentation + dir.getName() +" " + new Date(dir.lastModified()) );
}
public static void main(String[] argv) throws IOException
{
JFileChooser dialogue = new JFileChooser();
dialogue.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
PrintWriter ecrivain;
File fichier;
if (dialogue.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
{
fichier = dialogue.getSelectedFile();
ecrivain = new PrintWriter(new FileWriter
(fichier.getPath(), true));
}
listeur(new File("."));
System.exit(0);
}
////////////////////////////////////////////////////////////////////////////////
Le problème c'est que je ne sais pas comment faire pour qu'il utilise le dossier que jaurais selectionner, avec la fenetre ouvrir, pour faire mon affichage des fichiers
quelqu un a une idées et pourrait m'expliquer?
import java.io.*;
import javax.swing.JFileChooser;
import java.util.*;
class EssaiChoixFichier
{
static String indentation = new String();
public void listeur(File dir) {
process(dir);
if (dir.isDirectory()) {
String[] children = dir.list();
indentation += " ";
for (int i=0; i<children.length; i++) {
listeur(new File(dir, children[i]));
}
indentation = indentation.substring(0,indentation.length()-1);
}
}
public void process(File dir) {
try {
System.in.read();
System.in.read();
}
catch(IOException e){}
System.out.println(indentation + dir.getName() +" " + new Date(dir.lastModified()) );
}
public static void main(String[] argv) throws IOException
{
JFileChooser dialogue = new JFileChooser();
dialogue.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
PrintWriter ecrivain;
File fichier;
if (dialogue.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
{
fichier = dialogue.getSelectedFile();
ecrivain = new PrintWriter(new FileWriter
(fichier.getPath(), true));
}
listeur(new File("."));
System.exit(0);
}
////////////////////////////////////////////////////////////////////////////////
Le problème c'est que je ne sais pas comment faire pour qu'il utilise le dossier que jaurais selectionner, avec la fenetre ouvrir, pour faire mon affichage des fichiers
quelqu un a une idées et pourrait m'expliquer?
A voir également:
- Programmer un listeur de fichier
- Comment ouvrir un fichier epub ? - Guide
- Fichier bin - Guide
- Fichier rar - Guide
- Fichier .dat - Guide
- Comment ouvrir un fichier 7z - Guide
3 réponses
je ne C pas si j'ai bien compris ton probleme, mais si tu veux lister un dossier que tu auras chosi dans ta JFileChooser voila un bout de code (tres sommaire certe) mais qui marche :
cu
import java.io.*;
import javax.swing.JFileChooser;
import java.util.*;
class EssaiChoixFichier
{
JFileChooser JchooserDialog = new JFileChooser();
public void Select()
{
JchooserDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if (JchooserDialog.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
{
list(new File(JchooserDialog.getSelectedFile().getPath()));
}
}
public void list(File dir)
{
File[] files = dir.listFiles();
System.out.println(files.length + " fichier(s) contenu(s) dans : " + dir.getAbsolutePath() + " :");
for (int i=0; i<files.length;i++)
{
System.out.println(files[i].getName());
}
}
public static void main(String[] e)
{
EssaiChoixFichier l1 = new EssaiChoixFichier();
l1.Select();
System.exit(0);
}
cu