Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear the Contents of a File

Tags:

c#

.net

file

How does one clear the contents of a file?

like image 772
olive Avatar asked Feb 15 '11 04:02

olive


People also ask

How do you clear the contents of a file in Linux?

Empty or delete the contents of a large file using the truncate command in the Linux/Unix system. The truncate command is used to shrink or extend the size of a file to a specified size in the Linux system. It is also used to empty large file contents by using the -s option followed by 0 (zero) specified size.

How do you clear the contents of a file in bash?

You can use truncate. Save this answer.


1 Answers

You can use the File.WriteAllText method.

System.IO.File.WriteAllText(@"Path/foo.bar",string.Empty); 
like image 92
The Scrum Meister Avatar answered Sep 21 '22 21:09

The Scrum Meister