0

I have difficulties in developing a java code to remove an entire row in a file when you find the word "file error".

When code finds the phrase "file error" in the file (.txt), it should remove the whole line containing the phrase.

Could anyone help me?

Sebastian
  • 7,670
  • 5
  • 38
  • 50
user2530802
  • 119
  • 2
  • 10

1 Answers1

0

You can do with the following steps:

  • Create a temporary file
  • Open both the files. Original file for reading and temp file for writing
  • Read from the original file, line by line and write it into temp file
  • If the line contains text "file error" skip that line
  • Once reading is finished, delete the original file and rename the temp file to original file.
Darshan Mehta
  • 30,102
  • 11
  • 68
  • 102