salut a toutes et a tous !
je veux faire un programme Java permettant de lire un fichier composé de lignes de la forme « nom=valeur » tel que « nom » est une chaîne de caractères ne contenant pas « = » et valeur est un entier. Le programme doit vérifier si le fichier est bien écrit et répond ensuite aux requêtes des utilisateurs voulant connaître la valeur de tel ou tel nom.
et jusqu'a maintenant je suis arrivé a ça
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
| import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import java.util.regex.Pattern;
public class Properties {
public static void main(String[] args) throws IOException {
Path pa=Path.get("/home/poste1/Bureau/exo.txt");
byte[] b=File.readAllBytes(pa);
String fich=new String(b);
Pattern p=Pattern.compile("([a-zA-z]+=[0-9]+\r\n)+");
boolean bool = Pattern.matches("([a-zA-z]+=[0-9]+\r\n)+", fich);
if (bool) System.out.println("Fichier bien ecris");
else System.out.println("Fichier mal ecris");
Scanner sc=new Scanner(System.in);
System.out.println("entrer la nom: ");
String nom =sc.nextLine();
int i=fich.indexOf(nom)+nom.length()+1;
int j=fich.indexOf("\n",fich.indexOf(nom));
String valeur=fich.substring(i, j);
System.out.println(valeur);
}
} |
et il m'affiche une erreur au niveau de
Path pa=Path.get("/home/poste1/Bureau/exo.txt");
sachant que le problème n'est pas dans l'emplacement du fichier.txt mais dans la classe path ! comment régler ce problème ?
Partager