This kind of a nooby question. What is the most efficient and/or idiomatic way to clear the contents of a file using the standard library?
If the file is already open you can use .set_len(0)
. Else you can use std::fs::OpenOptions::new().truncate(true).open(path)
to open a file and truncate it at the same time.
3 Likes
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.