Java print specific data from file

By | July 12, 2018

I’ve a txt file. In there are rules and I have to get everything between the brackets in a separate file. But I don’t even get it shown in the console.

I already tried many methods, but i always get some errors.(outlined code)

With the solution right now, it just showing nothing in the console. Does anyone know why?

The brackets are always in the same line as “InputParameters” i tried something with that, at the end of the code.

The solutions that are outlined won’t work. Maybe someone got an idea?

with that code below i get the following error :

Exception in thread “main” java.lang.StringIndexOutOfBoundsException:
String index out of range: -1 at java.lang.String.substring(Unknown
Source) at blabla.execute.main(

here some content from the txt file:

dialect  "mvel"   
rule "xxx"  
        InputParameters (xy <= 1.124214, xyz <= 4.214214, abc <= 1.12421, khg <= 1.21421)   


Here is the code:

public class execute {

    public static void main(String[] args) throws IOException {
        BufferedReader br = null;

        try {
            br = new BufferedReader(new FileReader("C:\\users\\stn\\windowbuilder\\task.txt"));

            java.lang.String line;
            line = br.readLine();
            while ((line = br.readLine()) != null) {
                System.out.println(line.substring(line.indexOf(("\\("), line.indexOf(("\\)")))));

        } catch (FileNotFoundException e1) {


        } finally {
            try {
            } catch (IOException e) {

Leave a Reply

Your email address will not be published. Required fields are marked *