Groovy write to file (newline)

前端 未结 5 1541
你的背包
你的背包 2020-12-24 01:05

I created a small function that simply writes text to a file, but I am having issues making it write each piece of information to a new line. Can someone explain why it puts

5条回答
  •  我在风中等你
    2020-12-24 01:50

    I came across this question and inspired by other contributors. I need to append some content to a file once per line. Here is what I did.

    class Doh {
       def ln = System.getProperty('line.separator')
       File file //assume it's initialized 
    
       void append(String content) {
           file << "$content$ln"
       }
    }
    

    Pretty neat I think :)

提交回复
热议问题