Find a line in a file and remove it

后端 未结 16 1850
谎友^
谎友^ 2020-11-22 13:06

I\'m looking for a small code snippet that will find a line in file and remove that line (not content but line) but could not find. So for example I have in a file following

16条回答
  •  执念已碎
    2020-11-22 13:50

    Old question, but an easy way is to:

    • Iterate through file, adding each line to an new array list
    • iterate through the array, find matching String, then call the remove method.
    • iterate through array again, printing each line to the file, boolean for append should be false, which basically replaces the file

提交回复
热议问题