Tutorial :Read a file after a specific word using java



Question:

I have to read a file and write into another but after a specific word occurs something like hi. How can i do any help please.


Solution:1

Well, something along the lines of:

  1. Open the input file for reading
  2. Open the output file for writing
  3. Keep a boolean variable to say whether you're meant to be writing or not
  4. Read a line from the input file (or whatever your unit is)
  5. If the line is null, or the file is otherwise finished, go to step 8
  6. If you're meant to be writing, write it to the output file; otherwise, check whether the line contains the word you're interested in
  7. Go back to step 4 (this will be via a while loop, probably)
  8. Close the output file (in a finally block)
  9. Close the input file (in a finally block)

Now, that's a rough outline, and it skips details such as how you find the word in a line (what if it's in another word?) and whether you have to write out "half a line" if the word occurs in the middle of the line. However, it should be enough to get you started. If you have problems with any of the steps, please give more details so we can help you further.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »