Bonjour les amis, j'ai un petit problème.
je dois créer un programme qui génèrera un fichier d'importation pour un autre programme.
J'ai alors essayé quelque chose :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
public class FileChooser_APPROVE_SELECTION {
 
  public static void main(String[] argv) throws Exception {
    final Etudiant[] ecrireInfoEtudiant = new Etudiant[3];
    Etudiant[] lireInfoEtudiant = new Etudiant[3];
    ecrireInfoEtudiant[0] = new Etudiant("Laurent", "Surny", "B");
    ecrireInfoEtudiant[1] = new Etudiant("Salima", "Hassimi", "A");
    ecrireInfoEtudiant[2] = new Etudiant("Marie", "Dufour", "B+");
 
    MyFileChooser chooser = new MyFileChooser();
    chooser.setDialogType(JFileChooser.SAVE_DIALOG);
    final JDialog dialog = chooser.createDialog(null);
    chooser.addActionListener(new AbstractAction() {
      public void actionPerformed(ActionEvent evt) {
        JFileChooser chooser = (JFileChooser) evt.getSource();
        if (JFileChooser.APPROVE_SELECTION.equals(evt.getActionCommand())) {
        	//Sélection du chemin avec ajout de l'extension txt
        	File  fichier = new File(chooser.getSelectedFile()+".txt");
        	try {
        		//Création du nouveau fichier
				fichier.createNewFile();
				PrintWriter sortie = new PrintWriter(new BufferedWriter(new FileWriter(fichier)));
 
				for(int y = 0;y < 3;y++){
					sortie.println(ecrireInfoEtudiant[y]);
				}sortie.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();}
          dialog.setVisible(false);
        } else if (JFileChooser.CANCEL_SELECTION.equals(evt.getActionCommand())) {
          dialog.setVisible(false); }} });
 
    dialog.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        dialog.setVisible(false); } });
    dialog.setVisible(true);
  }}
class MyFileChooser extends JFileChooser {
  public JDialog createDialog(Component parent) throws HeadlessException {
    return super.createDialog(parent);
  }}
class Etudiant implements Serializable{
		String prenomEtudiant, nomEtudiant, noteEtudiant;
 
		public Etudiant(){
			super();};
		public Etudiant(String prenom,String nom,String note){
			prenomEtudiant = prenom;
			nomEtudiant = nom;
			noteEtudiant = note;}}
Le fichier texte est crée, mais le contenu est illisible :
FileChooser.Etudiant@811c88
FileChooser.Etudiant@785d65
FileChooser.Etudiant@3bc257
Aidez-moi s'il vous plaît.