logoalt Hacker News

vconnor • today at 12:41 PM • 0 replies • view on HN

Why would one would like to truncate an existing file? To overwrite it. It's a very common use case.

What I have never found any use for personally is opening a file in read-write mode, while also truncating it, which is the full extent of w+ behaviour. I cannot think of many reasons to have an output stream to also function as an input.