Reading File for specific string

The file i am reading is data saved from the Windows registry, so "UTF-16". It contains "empty/null" lines in which using BufferedReader and Scanner has been problematic for me. I am looking for a specific string inside the file, but it has been failing due to the "empty/null" lines in the file. This happens inside an actionEvent from a JButton. I've tested the JButton's actionEvent and it works.

tl;drI am asking:

how to find and replace all empty/null lines in file

"Skip" over the empty lines and continue looking for the specific string

Re: Reading File for specific string

Lines returned by a BufferedReader instance before the end of file won't be null, although they may be empty. An empty line can be treated like any other string that does not contain the string you are looking for: just increment the line count and move on.

It might help to post some actual code that is not behaving as you intend. A couple of problem solving techniques are to separate the searching logic from the event handling logic and just post a simple example of the problem without the GUI clutter. Another is to base the BufferedReader on a hard coded string rather than an actual file: this helps others here see the problem without having the file in question.

Re: Reading File for specific string

Originally Posted by pbrockway2

Lines returned by a BufferedReader instance before the end of file won't be null, although they may be empty. An empty line can be treated like any other string that does not contain the string you are looking for: just increment the line count and move on.

It might help to post some actual code that is not behaving as you intend. A couple of problem solving techniques are to separate the searching logic from the event handling logic and just post a simple example of the problem without the GUI clutter. Another is to base the BufferedReader on a hard coded string rather than an actual file: this helps others here see the problem without having the file in question.

Thank you very much! I completely forgot about isEmpty, just made a conditional and works