Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Scanning groups of lines

owanowan Member Posts: 1
Being quite new to Java I would appreciate some tips on how to use the scanner. Need to parse rather large text files and have considered some different approaches - each with different problems, and can't decide which one is best.

The text format is something like this:
The file may start with any text for a number of lines. After a line break
[Date Time andAnyCharactersWithinBraces] Followed by text that could contain [Date time] and
span over several lines.
[Date Time andAnyCharactersWithinBraces] This is just another one...

For me the most obvious way would be to scan using a regexp delimiter matching the
[Date Time Tag]. Trying that I sometimes get
[Date Time Tag] Some text...]. This could probably be solve by using something like ^] instead of .*. But how do I get hold of the string that was matching? It seems I have ruled out the possibility to read [Date Time Tag] that should be connected to the text...

One other approach would be to read to EOF. This I think would work, but files are rather large (5-10MB). If I set the buffer to lower than the file size, wouldn


  • silveredge52silveredge52 Member Posts: 198
    It is not clear to me what the program is supposed to find during parsing. What are the target string(s)? Define what condition(s) signifies the begining of a target string, and what condition(s) signifies the end of a target string.

    If a target string can span input records consider using a [link=]StringBuilder [/link]to hold the input lines that are needed to find a single target string.

    An example of a stream sample would help. Also the regular expression that is being used to satisfy the requirement is needed.
Sign In or Register to comment.