.NET File.WriteAllLines leaves empty line at the end of file

前端 未结 9 1129
情歌与酒
情歌与酒 2020-12-17 17:58

When I\'m saving content of the String[] array with System.IO.File.WriteAllLines, at the end of a file is always left a blank line. For example:

System.IO.Fi         


        
9条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-17 18:48

    The WriteAllLines method will write out each line in your array followed by a line break. This means that you will always get this "empty line" in your file.

    The point made in the post you linked is that when running ReadAllLines that considers a line to be characters terminated by a line break. So when you use the read method on the file you've just written you should get the exact same lines back.

    If you are reading the file in a different way then you will have to deal with linebreaks yourself.

    Essentially what you are seeing is Expected Behaviour.

提交回复
热议问题