How can I delete the content of a file in Java?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
You could do this by opening the file for writing and then truncating its content, the following example uses NIO:
Another way: truncate just the last 20 bytes of the file:
This code will remove the current contents of 'file' and set the length of file to 0.
Open the file for writing, and save it. It delete the content of the file.
How about this:
May problem is this leaves only the head I think and not the tail?