In my opinion, a text file consists of lines of text. Lines end with a sequence of lines whose exact details are platform dependent. Thus, the correct text file should always contain exactly 1 sequence of lines per line.
In any case, you could probably solve this problem by either processing the last line differently, or by creating the entire file in memory and writing it as binary data, for fear of omitting the last one or two bytes, depending on your platform, the exact feed sequence format.
source share