0

I am trying to search for regular expressions in a string created by StringBuilder() as follows

public String config( String langage ) throws IOException {
    BufferedReader reader = new BufferedReader(new FileReader (dir_user+"/.prochic/"+langage));

    //System.out.println(getAbsolutePath());
    String         line = null;
    StringBuilder  stringBuilder = new StringBuilder();
    String         ls = System.getProperty("line.separator");

    try {
    while( ( line = reader.readLine() ) != null ) {
        stringBuilder.append( line );
        stringBuilder.append( ls );
    }

    return stringBuilder.toString();

    } finally {
    reader.close();
    }
};

and then

String text=config(langage);

However, I can't do something like

System.out.println(text[5]);

How can I access (or print) the different components (characters) of my string?

1
  • You can use new String(Files.readAllBytes(Paths.get(language), StandardCharsets.UTF_8) however you may want to process each line as you read it instead. e.g. File.lines Commented Feb 15, 2016 at 14:14

1 Answer 1

2

I think you are looking for .charAt():

System.out.println(text.charAt(5));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.