The easiest way is to simply read the entire file, delete the "\ n" at the end, and overwrite it all with your own content:
filename = "imcs2.xml"
content = File.open(filename, "rb") { |io| io.read }
File.open(filename, "wb") { |io|
io.print content.chomp
io.print "yourstuff"
}
Alternatively, simply io.seek () back along the last new line, if any:
filename = "imcs2.xml"
File.open(filename, "a") { |io|
io.seek(-1, IO::SEEK_CUR)
io.print "yourstuff"
}
source
share