How can I delete a specific string in a text file?
相关问题
- 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
Locate the file.
Create a temporary file (otherwise you've to read everything into Java's memory first).
Determine the charset.
Determine the string you'd like to delete.
Open the file for reading.
Open the temp file for writing.
Read the file line by line.
Delete the string from the line.
Write it to temp file.
Close the reader and writer (preferably in the
finally
block).Delete the file.
Rename the temp file.
See also: