Comment passer un parametre??

zebulaon Messages postés 15 Date d'inscription mercredi 15 janvier 2003 Statut Membre Dernière intervention 19 février 2003 - 27 janv. 2003 à 12:37
zebulaon Messages postés 15 Date d'inscription mercredi 15 janvier 2003 Statut Membre Dernière intervention 19 février 2003 - 28 janv. 2003 à 10:46
Bonjour, je cherche à passer un parametre à mon prog java, lors du lancement je dois specifier en mode console, le nom du fichier qui sera traité par le prog!
EX: C:\ JAVA TOTO C:\Rep1\SSRep2\monfichier.dll

J'aimerai pouvoir l'integrer en dur ds le main....
Afin de lancer uniquement
C:\ JAVA TOTO

public class Toto{
public static void main(String[] args) {
new titi.tito(args);
}
}

Merci

3 réponses

JHelp Messages postés 261 Date d'inscription jeudi 5 septembre 2002 Statut Membre Dernière intervention 6 octobre 2005 11
28 janv. 2003 à 08:08
La solution peut être par exemple :
0
JHelp Messages postés 261 Date d'inscription jeudi 5 septembre 2002 Statut Membre Dernière intervention 6 octobre 2005 11
28 janv. 2003 à 08:13
Une solution :

public class Toto
{
  public static void main(String[] args) 
  { 
     String[] tab=new String[2];
      tab[0]=args[0];
     if(args.length<2)
          tab[1]="C:\Rep1\SSRep2\monfichier.dll";
      else
          tab[1]=args[1];
     new titi.tito(tab);
  }
}


JHelp
0
zebulaon Messages postés 15 Date d'inscription mercredi 15 janvier 2003 Statut Membre Dernière intervention 19 février 2003
28 janv. 2003 à 10:46
-------------------------------
Réponse au message :
-------------------------------

Merci bcp pour ton aide, elle ressemble bcp à celle que j'ai finalement trouvé... Pour ceux & celles à qui cela peut aider voici une autre solution qui permet en plus d'avoir des parametres de traiments fichiers en dur, une possibilité de parametres consoles!
Merci encore Jhelp

public class Toto {
public static void main(String[] args) {

String [] tab = new String [args.length+3];
for (int i=0; i<args.length; i++)
tab[i]=args[i];

tab[args.length]="C:\Rep1\SSRep2\monfichier.dll";
tab[args.length+1]="C:\Rep1\SSRep2\monfichier2.dll";
tab[args.length+2]="C:\Rep1\SSRep2\monfichier3.dll";
for (int j=0; j<tab.length; j++)
System.out.println(tab[j]);
System.out.println("");
new titi.tito(tab);
}
}
0
Rejoignez-nous