Deleting a specific line in a text file?
问题 How can I delete a single, specific line from a text file? For example the third line, or any other line. I tried this: line = 2 file = File.open(filename, 'r+') file.each { last_line = file.pos unless file.eof? } file.seek(last_line, IO::SEEK_SET) file.close Unfortunately, it does nothing. I tried a lot of other solutions, but nothing works. 回答1: I think you can't do that safely because of file system limitations. If you really wanna do a inplace editing, you could try to write it to memory,