Java extract text from text file from a certain point on the text

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: ")){
            id = ligne;
        if(ligne.startsWith("Pass: ")){
            pass = ligne;
} 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.


Source: java

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.