IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Agents de placement/Fenêtres Java Discussion :

java - Problème JFileChooser - dernier répertoire


Sujet :

Agents de placement/Fenêtres Java

  1. #1
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2016
    Messages
    213
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2016
    Messages : 213
    Points : 96
    Points
    96
    Par défaut java - Problème JFileChooser - dernier répertoire
    Salut à tous,

    J'ai un petit problème je pense.
    Lorsque que je fais ceci ça fonctionne mais vu qu'il y a ces lignes en commentaires ça ne renouvelle pas le dernier chemin :
    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
    public File fileChooser()
    {
    	Preferences prefs = Preferences.userNodeForPackage(FileChooser.class);
    	FileChooser.lastPath = prefs.get("LastPath", System.getProperty("user.dir"));
    	this.setCurrentDirectory(new File(lastPath));
    	if (this.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
    	{
    		final double ratio = 0.009900990099009901;
    		ZipSecureFile.setMinInflateRatio(ratio);
     
    		File file = this.getSelectedFile();
    		//file = this.getCurrentDirectory();
    		//prefs.put("LastPath", file.getAbsolutePath());
    		//file.setWritable(true);
     
    		return file;
    	}
    	return null;
    }
    Et si j'enlève les // alors j'ai un Exception :
    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
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    java.io.FileNotFoundException: M:\H2O (Accès refusé)
    	at java.io.FileInputStream.open(Native Method)
    	at java.io.FileInputStream.<init>(Unknown Source)
    	at EVENT.UtilityMethods.excelHDTM2Data(UtilityMethods.java:297)
    	at EVENT.UtilityMethods.readDataHDMT(UtilityMethods.java:270)
    	at EVENT.Events.btnLoad_click(Events.java:170)
    	at EVENT.Events.actionPerformed(Events.java:105)
    	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    	at javax.swing.plaf.basic.BasicButtonListener$Actions.actionPerformed(Unknown Source)
    	at javax.swing.SwingUtilities.notifyAction(Unknown Source)
    	at javax.swing.JComponent.processKeyBinding(Unknown Source)
    	at javax.swing.KeyboardManager.fireBinding(Unknown Source)
    	at javax.swing.KeyboardManager.fireKeyboardAction(Unknown Source)
    	at javax.swing.JComponent.processKeyBindingsForAllComponents(Unknown Source)
    	at javax.swing.JComponent.processKeyBindings(Unknown Source)
    	at javax.swing.JComponent.processKeyEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
    	at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
    	at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
    	at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
    	at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    	at java.awt.EventQueue.access$000(Unknown Source)
    	at java.awt.EventQueue$1.run(Unknown Source)
    	at java.awt.EventQueue$1.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue$2.run(Unknown Source)
    	at java.awt.EventQueue$2.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    java.io.FileNotFoundException: D:\Users\t0163126\Documents\Mes Outils Personnels (Accès refusé)
    	at java.io.FileInputStream.open(Native Method)
    	at java.io.FileInputStream.<init>(Unknown Source)
    	at EVENT.UtilityMethods.excelHDTM2Data(UtilityMethods.java:297)
    	at EVENT.UtilityMethods.readDataHDMT(UtilityMethods.java:270)
    	at EVENT.Events.btnLoad_click(Events.java:170)
    	at EVENT.Events.actionPerformed(Events.java:105)
    	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    	at javax.swing.plaf.basic.BasicButtonListener$Actions.actionPerformed(Unknown Source)
    	at javax.swing.SwingUtilities.notifyAction(Unknown Source)
    	at javax.swing.JComponent.processKeyBinding(Unknown Source)
    	at javax.swing.KeyboardManager.fireBinding(Unknown Source)
    	at javax.swing.KeyboardManager.fireKeyboardAction(Unknown Source)
    	at javax.swing.JComponent.processKeyBindingsForAllComponents(Unknown Source)
    	at javax.swing.JComponent.processKeyBindings(Unknown Source)
    	at javax.swing.JComponent.processKeyEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
    	at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
    	at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
    	at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
    	at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    	at java.awt.EventQueue.access$000(Unknown Source)
    	at java.awt.EventQueue$1.run(Unknown Source)
    	at java.awt.EventQueue$1.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue$2.run(Unknown Source)
    	at java.awt.EventQueue$2.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    Ce qui correspond à :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    InputStream is = new PushbackInputStream(new FileInputStream(file));

  2. #2
    Membre habitué
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Août 2011
    Messages
    584
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Août 2011
    Messages : 584
    Points : 181
    Points
    181
    Par défaut
    Bonjour,
    le message d'erreur indique que le fichier n'est pas trouvé à cause d'un problème de droits :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    java.io.FileNotFoundException: M:\H2O (Accès refusé)
    Le fichier est il sur la partition principal de ta machine, es tu le propriétaire du fichier ?
    Tu peux essayer de lancer ton application en tant qu'administrateur voir si ça fonctionne.

  3. #3
    Modérateur
    Avatar de joel.drigo
    Homme Profil pro
    Ingénieur R&D - Développeur Java
    Inscrit en
    Septembre 2009
    Messages
    12 430
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur R&D - Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2009
    Messages : 12 430
    Points : 29 131
    Points
    29 131
    Billets dans le blog
    2
    Par défaut
    Salut,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    File file = this.getSelectedFile();
    file = this.getCurrentDirectory();
    prefs.put("LastPath", file.getAbsolutePath());
    Forcément, ta variable file servant à référencer le fichier sélectionné, et vu que tu l'écrase avec le dossier courant, tu perds le fichier sélectionné. Ensuite, le reste du code, qui fait un new FileInputStream(file) va essayer d'ouvrir un dossier comme si c'était un fichier, ce qui est impossible, voire absurde.

    Si tu veux mémoriser dans les préférences le dossier du dernier fichier sélectionné :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    File file = this.getSelectedFile();
    prefs.put("LastPath", file.getParentFile().getAbsolutePath());

  4. #4
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2016
    Messages
    213
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2016
    Messages : 213
    Points : 96
    Points
    96
    Par défaut
    En effet c'est absurde, en tout cas pour ton code, MERCI, ça fonctionne...

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [DOM][Java] Problème avec le retour de getNodeName()
    Par anutka dans le forum XML/XSL et SOAP
    Réponses: 3
    Dernier message: 11/04/2012, 21h38
  2. Problème avec JFileChooser et répertoire sur un poste distant.
    Par Dambrath dans le forum Agents de placement/Fenêtres
    Réponses: 1
    Dernier message: 11/05/2009, 15h34
  3. [Java] Problème ClassPath
    Par nsanabi dans le forum Jasper
    Réponses: 8
    Dernier message: 02/11/2005, 18h44
  4. [JAVA] Problème supression noeud d'un document XML
    Par vero59 dans le forum XML/XSL et SOAP
    Réponses: 10
    Dernier message: 16/08/2005, 16h12
  5. [Eclipse][Java]Problème de compilation sur CTRL+S
    Par ZeKiD dans le forum Eclipse Java
    Réponses: 5
    Dernier message: 27/05/2004, 11h49

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo