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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
| public static void main(String[] args) throws IOException
{
Scanner saisie=new Scanner (System.in);
int choix=0;
boolean varfinprog=false;
String nomfich;
String nomfich2;
String ligne;
String resultat;
boolean finecriture=false;
while(varfinprog==false)
{
System.out.println("*****************************");
System.out.println("* MENU - Gestion de données *");
System.out.println("* 1-Année *");
if (choix==1)
{
System.out.println("* \t 11-Lister *");
System.out.println("* \t 12-Ajouter *");
System.out.println("* \t 13-Modifier *");
}
System.out.println("* 2-Pays *");
if (choix==2)
{
System.out.println("* \t 21-Lister *");
System.out.println("* \t 22-Ajouter *");
System.out.println("* \t 23-Modifier *");
}
System.out.println("* 3-Ville *");
if (choix==3)
{
System.out.println("* \t 31-Lister *");
System.out.println("* \t 32-Ajouter *");
System.out.println("* \t 33-Modifier *");
}
System.out.println("* 4-Quitter *");
System.out.println("*****************************");
System.out.print("Faites votre choix: ");
try
{
choix=saisie.nextInt();
}
catch (Exception e)
{
System.out.println("Erreur saisie veuillez relancer le programme");
varfinprog=true;
}
if (choix==4) {varfinprog=true;}
switch (choix)
{
case 11 :
nomfich= "année.txt";
BufferedReader entree = new BufferedReader (new FileReader(nomfich));
do
{
ligne=entree.readLine();
if(ligne != null) System.out.println(ligne);
}while (ligne != null);
entree.close();
System.out.println("**Fin lecture fichier Année**");
System.out.println("");
break;
case 12 :
{ try {
String file = "C:\\Users\\33638\\Desktop\\année.txt";
Scanner clavier=new Scanner(System.in);
do
{
System.out.print("Taper votre année, Q pour sortir ");
resultat=clavier.nextLine();
if ((finecriture==false)&(resultat.compareTo("Q")!=0)) {
String lineToAppend = "\r"+resultat;
byte[] byteArr = lineToAppend.getBytes();
Files.write(Paths.get(file), byteArr, StandardOpenOption.APPEND);}
if (resultat.compareTo("Q")==0) {
finecriture=true;
}
}while (finecriture==false);
} catch (Exception e) {
System.out.println(e);
}
System.out.println("**Année ajouté avec succes***");}
break;
case 13 :
//modifier le fichier année
break;
case 21 : System.out.println("*EXECUTION METHODE 21*"); break;
case 22 : System.out.println("*EXECUTION METHODE 22*"); break;
case 23 : System.out.println("*EXECUTION METHODE 23*"); break;
case 31 : System.out.println("*EXECUTION METHODE 31*"); break;
case 32 : System.out.println("*EXECUTION METHODE 32*"); break;
case 33 : System.out.println("*EXECUTION METHODE 33*"); break;
}
}
}
} |
Partager