How can I delete the first two rows of a text file with 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
This works if you wish to reference the lines to exclude, by index, like in the example you gave. And it does not load the entire file into memory.
Read the file and write back everything but the first two rows.
Very good example of reading a file here: http://www.kodejava.org/examples/266.html
Here is a Guava solution:
Yes, the entire file is read into memory, so don't try this with huge server log files.
Here is how I am deleting first 20 lines from the targetFile...
}
Here's how: