1) Is that as complex as the log file gets, or is it only ever a list of names (in form //NAME) immediately followed by the line with the value.
2) Is the String in the left hand square bracket important, or do you only want the String in the right hand square bracket.
Assuming that that is as complex as the file gets and you only ever want to map the name in the comment to the value in the right hand bracket I would:
* Loop through the contents of the file line by line, finding each instance of the names.
* When a name is found, read the following line and use a regular expression to extract the value in the right hand side square bracket. This will be simple if the logs are only ever in the format you show there.
* Store the name and the value in a Map, so you can look up the values using the name you want.
If the log file can have a more complex structure or you need other information from it then the approach I mentioned may not be the best.
Also, this isn't really a beginning Java question.
1) I don't know what regular expression can i use.
2) I want a line to check that preceding line should have //StorageVersion .
3) n then i will check any string between := K[' and '];. From above log file "'706146.0.22106932'" is the value that i am looking for.
If this was my problem I'd write a lexer for this format. In my experience, such formats only ever tend to get more complex, and maintaining a handwritten parser leads to headaches. I wrote an introduction to lexers some years ago.
posted 5 years ago
Logs file will not become complex. Structure will remain the same and just the "StorageValue" keeps on chaging
I'm not dead! I feel happy! I'd like to go for a walk! I'll even read a tiny ad:
Try Free Java/.NET Libraries for Word Excel PowerPoint and PDF