how to clear file before writing to it again

Sukandar Kartadinata's icon

so I created a new file with File() and File.writebytes(), and now I want to write to it again with updated content. What happens, currently, is that if the new content is shorter than the previous content, part of the latter is still visible.
So how do I clear the contents before writing new stuff?
(in "normal" Javascript I do seek(0) followed by truncate() but that doesn't work here)

thanks, Sukandar

Torsten's icon

same problem here

klaus filip's icon
Sukandar Kartadinata's icon

thanks Klaus :)