0

i have this code that prints in the same line after each loop. For example:

"categorie=extragraphique","remarque=confusion_consonne","mot=article","categorie=logogrammique","remarque=aposthrophe","mot=conjonction"

i would like a linebreak after each loop but /n doesnt work and writeLine will do a different thing.

The wanted output is: "categorie=extragraphique","remarque=confusion_consonne","mot=article" "categorie=logogrammique","remarque=aposthrophe","mot=conjonction"

  new File("/outfile.txt").withWriterAppend{ out ->
  (doc.getNamedAnnotationSets() + [Default:(doc.getAnnotations())]).each{ setName, set ->
    set.each{ anno ->
      if( anno.getFeatures() )
        anno.getFeatures().each{ fValue ->
          out.write(/"${fValue}",/)
        }
      else
        out.write(/"${anno.getId()},,/)        
    }
  }
}

Thnaks in advance

  • It looks like a pure groovy question, check this: https://stackoverflow.com/questions/4272330/groovy-write-to-file-newline – Yasen Aug 02 '18 at 08:36
  • I don't understand the statement > _`/n` doesnt work and writeLine will do a different thing_ Can you explain it in more detail? The code looks like from a groovy expert, what are you struggling with? – dedek Aug 02 '18 at 12:22

1 Answers1

0

What about:

  new File("/outfile.txt").withWriterAppend{ out ->
  (doc.getNamedAnnotationSets() + [Default:(doc.getAnnotations())]).each{ setName, set ->
    set.each{ anno ->
      if( anno.getFeatures() )
        anno.getFeatures().each{ fValue ->
          out.write(/"${fValue}",/)
        }
      else
        out.write(/"${anno.getId()},,/)        

      out.write('\n') //this line is new
    }
  }
}
dedek
  • 7,981
  • 3
  • 38
  • 68