Use Groovy To Search A File And Grab Contents Below A String -


I'm trying to use Groovy to open a file to search for a specific substring, and then down One of the first things I get hold of is a different object.

For example, I'm searching the substring "Charger is enabled. Checking the charging parameters ..." and if it is found that I want to get a special string that happens later is.

Is this the best way to do this is to read the file in memory and discover the first string index?

  // Java import with java.io.file; Import java.io.buffferedReader; Import java.io.fileReader; Def locale directory = ""; Def fileName = ""; Def Search = "Charger is Enabled. Checking Charging Criteria"; Deff Search 2 = ""; Def error message = ""; Flamerdid Frey; Bufrederer br; {Try File F1 = New File (Local Directory + "/" + Filename); Fr = new FileReader (f1); Br = new buffed reader (FR); Def keyfound = false; Go line line via line // line; While ((line = br.readLine ())! = Null {// If the first string is found, then do the second string process if (line contents)} {while ((line = br.readline ())! = Null) {// Do something with the second string. If (line condition (2 of findings)) {keyFound = true; break; }}} If (keyfound) {break; }}} Hold (exception e) {errorMessage + = "\ n unexpected exception:" + e.getMessage (); For (trace in e.getStackTrace ()) {error message + = "\ n \ t" + trace; }} Finally {F.R. ? Br .close (); } // Groovy def with the local directory = ""; Def fileName = ""; Def Search = "Charger is Enabled. Checking Charging Criteria"; Deff Search 2 = ""; Def error message = ""; {Try File F1 = New File (Local Directory + "/" + Filename); Def keyfound = false; Go line line via line // line; F1.withReader {Reader - & gt; {(Line = Reader. Readline ()) = Null {// If the first string is found, then process the second string if (line containings) {while ((line = reader.readline ()) ! = Null) {// Do something with the second string. If (line condition (2 of findings)) {keyFound = true; break; }}} If (keyfound) {break; }}}} Hold (exception e) {errorMessage + = "\ n unexpected exception:" + e.getMessage (); For (trace in e.getStackTrace ()) {error message + = "\ n \ t" + trace; }}  

Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -