I am new to Java and OOP.
Can you help me with the following problem?
I am reading a file and I need to take/print only the line that start with "#" sign and next line. My problem is that I do not know how to take only these 2 lines.
- find out how to iterate over individual lines of a text file.
- read Java API how to check if a String starts with a certain substring or how regular expressions can help.
- if you found a line starting with '#' remember that fact in a boolean type variable.
- after processing the next line reset that boolean type variable.
- print lines only if that boolean type variable is true.
Once you get it working, you should also consider edge conditions:
1: what if the current and next line both start with #
2: what if the last line in the file starts with #, and since its the last line, there is no line after it.
3: what if the file contains no lines that start with #.
Sorry about complicating your life, but a guy's got to have a hobby ;)