Choix de fichier à ouvrir
Bonsoir,
Pourriez vous me dire qu'est ce qui cloche dans ce programme, car quand je clique sur ouvrir, j'ai une exception qui est déclenchée :
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at Choix.main(Choix.java:18)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
import java.io.File;
import java.io.PrintWriter;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.JFileChooser;
class Choix {
public static void main(String[] arg) throws IOException {
JFileChooser dialogue = new JFileChooser(new File("."));
PrintWriter sortie;
File fichier;
if (dialogue.showOpenDialog(null)==
JFileChooser.APPROVE_OPTION) {
fichier = dialogue.getSelectedFile();
sortie = new PrintWriter
(new FileWriter(fichier.getPath(), true));
sortie.println(arg[0]);
sortie.close();
}
}
} |
Une fois le fichier choisi, je voudrai l'utiliser donc sauvegarder son contenu quelque part.
Merci.