i have this method to read data from a text file.

Code:

    StringBuffer fileData = new StringBuffer(1000);
    BufferedReader reader = new BufferedReader(new FileReader(filePath));
    char[] buf = new char[1024];
    String line;
      while ((line=reader.readLine())!=null){
        String f[] = line.split("\t");
            if (line.contains(loginname))
    {
   fileData.append(line);
    }
}
    reader.close();
    return fileData.toString();

If i have a text file with data like this

Username: faton
password: 6655

i want to read in to my string only the words faton and not the whole string Username: faton
Any help?

Read in the entire String, then lop-off what you don't need.

but i dont know how to do this. can you give me some help please?

Read the API docs for String. The methods you're interested in are
1) substring, combined with indexOf
or
2) replaceFirst / replaceAll

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.