I have created a method, with BufferedReader
that open a text file created previously by the program and extract some characters. My problem is, at the moment, it extracts the whole line and I want to extract only after a specified character, the :
This is the try/catch block i made:
try {
InputStream ips = new FileInputStream("file.txt");
InputStreamReader ipsr = new InputStreamReader(ips);
BufferedReader br1 = new BufferedReader(ipsr);
String ligne;
while((ligne = br1.readLine()) != null){
if(ligne.startsWith("Identifiant: ")){
System.out.println(ligne);
id = ligne;
}
if(ligne.startsWith("Pass: ")){
System.out.println(ligne);
pass = ligne;
}
}
System.out.println(ligne);
System.out.println(id);
System.out.println(pass);
br1.close();
} catch (Exception ex){
System.err.println("Error. "+ex.getMessage());
}
At the moment, I return to my String id the entire ligne
, and same for pass
. By the way, all the sysout
are test and are useless there.
If anybody know how to send to id the line after the :
and not the entire line, I probably searched bad, but google wasn’t my friend..
Thanks in advance.
Regards,
Source: java