2

I have txt file formatted kinda like this:

*FIELD_NAME NUMBER_OF_ELEMENTS
   ELEMENT
      *ANOTHER_FIELD NUMBER
         something
      #ANOTHER_FIELD
   ELEMENT
      *ANOTHER_FIELD NUMBER
         something
      #ANOTHER_FIELD
#FIELD_NAME

and I want to parse it using Java. This object might be similar to JSON

data sample:

*AAA 2
   1   FooBar
      *BBB  3
         101   2   
            Java
            Json
         102   2
            C++
            Another String
         103   1
            Stack
      #BBB
   2   BarFoo
      *BBB  2
         201   2
            over
            flow
         202   1
            it's the end of the file as we know it
      #BBB
#AAA

Appropriate structure to hold this data might be something like:

public class MyStruct {
   String name;
   List<MyStruct> elements;
}

but any ideas how to parse it?

0

1 Answer 1

1

I recommend using some parsing library to generate AST.

Most popular in java are:

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.