Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear a text file without deleting it using groovy

Tags:

groovy

I've a text file which I'll be using it to write content.. But every time before I write something to the file, I wish to clear the content without deleting the file..

How would I achieve the above? Any suggestions?

like image 660
Umesh Kumar Avatar asked Aug 07 '17 14:08

Umesh Kumar


People also ask

How would you empty the content of a file without deleting the file?

If you're working at the command line and need to quickly empty the contents of a file, you can do so by throwing a greater than symbol and a space in front of the filename in question.

How do you clear a text file in Java?

delete() method. In Java, we can delete a file by using the File. delete() method of File class. The delete() method deletes the file or directory denoted by the abstract pathname.


1 Answers

With text files you can simply set it to an empty string.

file.text = ''
like image 55
cjstehno Avatar answered Sep 20 '22 13:09

cjstehno