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);
}
} |