Probleme avec JFileChooser

Résolu/Fermé
Evan59245 Messages postés 60 Date d'inscription vendredi 26 avril 2013 Statut Membre Dernière intervention 18 février 2019 - 17 sept. 2015 à 11:46
Evan59245 Messages postés 60 Date d'inscription vendredi 26 avril 2013 Statut Membre Dernière intervention 18 février 2019 - 23 nov. 2015 à 14:26
Bonjour,

J'ai un problème dans mon programme, j'ai écris dans mon programme un JFileChooser qui permet d'aller chercher le fichier souhaité et ensuite d'un mon programme j'ai fais un nouveau JFileChooser pour choisir le répertoire ou je veux enregistrer mon fichier, mais le second ne s'affiche pas quand je lance mon programme je ne sais pas pourquoi...

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ged;

import java.awt.Component;
import java.io.File;
import java.util.Scanner;
import javax.swing.JFileChooser;

/**
 *
 * @author Evan
 */
public class GED {
    private static String Nom_Client;
    private static String N_plan;
    private static String ind;
    private static String Reference;
    private static String Typologie;

    public static void main(String[] args) throws Exception {
        // TODO code application logic here
        
        System.out.println("****************** TPS Gestionnaire ******************");
        System.out.println(" ");
        
        System.out.println("Quel fichier choisissez vous ?");
        JFileChooser file = new JFileChooser();
        file.setMultiSelectionEnabled(true);
            int retour = file.showOpenDialog(null);
                if(retour == JFileChooser.APPROVE_OPTION)
                {
                    File[] fichier=file.getSelectedFiles();
                        for( int i = 1; i<fichier.length; ++i)
                        { 
                        fichier[i].getAbsolutePath();
                        }
                        System.out.println("Fichier choisi : " + file.getSelectedFile().getName());
                }
                else
                {
                    System.out.println("Aucun de fichier choisi");
                }    
            
            
        System.out.println (" ");

        System.out.println("Veuillez indiquer le nom du client");
        Scanner name = new Scanner (System.in);
        String Nom_Client = name.nextLine();
        System.out.println("L'entreprise est: " + Nom_Client.toUpperCase());
        
        System.out.println ("Dans quel sous doussier souhaitez vous mettre votre document ?");
        System.out.println (" ");
        System.out.println ("1." + " PV Contrôle ");
        System.out.println ("2." + " Plan ");

        Scanner sr = new Scanner (System.in);
        int i = sr.nextInt();
        Categorie c = new Categorie (Nom_Client.toUpperCase(),"0","0","0","0");
        if (i==1)
            {
                c.PVControle();
            }
        else
            {  
                c.Plan();

                System.out.println (" Veuillez choisir la nouvelle destination du fichier");
                System.out.println(" ");
                
                JFileChooser newdestination = new JFileChooser();
                newdestination.setCurrentDirectory(new File("/Users/Evan/"));//Chemin
                newdestination.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                newdestination.setMultiSelectionEnabled(false);
                int dest = newdestination.showOpenDialog(null);
                    if(dest == JFileChooser.APPROVE_OPTION)
                    {
                    File[] fichier02=newdestination.getSelectedFiles();
                        for( int t = 1; t<fichier02.length; ++t)
                        { 
                        fichier02[t].getAbsolutePath();
                        }
                    System.out.println("Destination choisie : " + newdestination.getSelectedFile().getName());        

                    System.out.println(" Votre fichier à été renommé puis déplacé");        
                    }
                    else
                    {
                    System.out.println("Aucune destination choisie");
                    }
                    File source = file.getSelectedFile(); //Permet de récupérer le chemin du début
                    File destination = new File (newdestination.getSelectedFile() + Nom_Client.toUpperCase()+" "+ c.getN_plan()+ " " + "Ind" + " "+ c.getind().toUpperCase() +".pdf"); // Permet d'avoir la nouvelle destination avec le fichier renommé
                    source.renameTo(destination);
            }
        
    }
    
}


Help plz j'ai vraiment besoin d'aide

Cdt
Evan Martho

1 réponse

greg6614 Messages postés 592 Date d'inscription vendredi 7 août 2009 Statut Membre Dernière intervention 3 juin 2017 107
6 nov. 2015 à 14:45
Hello, essai de commenter cette ligne
newdestination.setCurrentDirectory(new File("/Users/Evan/"));


Ton chemin d'accès est spécifié bizarrement car ici tu impliques qu'il y a un dossier "/Users/Evan" dans le dossier d'exécution actuel qui est normalement ton WS.

Si tu penses au dossier utilisateurs de windows je verrai plutôt
newdestination.setCurrentDirectory(new File("C:/Users/Evan/"));

0
Evan59245 Messages postés 60 Date d'inscription vendredi 26 avril 2013 Statut Membre Dernière intervention 18 février 2019
23 nov. 2015 à 14:26
Désolé de voir seulement ta réponse, merci à toi !

Bonne journée :)
0