Semyazas Posted June 12, 2006 Share Posted June 12, 2006 Bonjour, je cherche un moyen d'acceder en absolu au répertoire oú se situe mon application Java à partir de l'application même. (éxécution d'une commande DOS et création d'un fichier dans ce répertoire). Pour exemple ma commande s'apparente à ceci : cmd = path+"bin\\mysqldump -u "+login+" -p "+password+" "+base+" > "+ [ce que je cherche]; try { Runtime r = Runtime.getRuntime(); Process p = r.exec(cmd); p.waitFor(); }catch(Exception ex) { System.out.println("erreur d'execution " + cmd + e.toString()); } Link to comment Share on other sites More sharing options...
Sentinel Posted June 12, 2006 Share Posted June 12, 2006 (new File(".")).getCanonicalPath() ? Link to comment Share on other sites More sharing options...
fabien29200 Posted June 13, 2006 Share Posted June 13, 2006 String currentPath = System.getProperty("user.dir"); voili, voilou Link to comment Share on other sites More sharing options...
Sentinel Posted June 13, 2006 Share Posted June 13, 2006 Pas du tout... Ta commande te donne le répertoire personnel de l'utilisateur (/home/XXX sous linux, C:/Mes documents/... sous windows). Si tu lances ton appli à partir de ce répertoire c'est bon, sinon c'est raté. Ma commande en revanche te donne véritablement le répertoire racine de ton application. Link to comment Share on other sites More sharing options...
fabien29200 Posted June 13, 2006 Share Posted June 13, 2006 Dixit l'API 1.4.2 de Sun (classe System). user.name User's account nameuser.home User's home directory user.dir User's current working directory Exemple : package com.test; /** * @author fabien * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ public class Test { public static void main(String[] args) { System.out.println("Repertoire courant :"); System.out.println(System.getProperty("user.dir")); } } Lancement : fabien@Dauntless /usr/src $ java -cp /home/fabien/test.jar com.test.Test Repertoire courant : /usr/src Désolé Sentinel Link to comment Share on other sites More sharing options...
Sentinel Posted June 13, 2006 Share Posted June 13, 2006 han j'ai confondu avec user.home Mais ! Ma méthode marche aussi (bon ok c'est moins propre j'avoue) (un partout ) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.