So I'm reading a plain text file in Java, and I'd like do identify which lines start with "abc". I did the following:
Charset charset = StandardCharsets.UTF_8; BufferedReader br = Files.newBufferedReader(file.toAbsolutePath(), charset); String line; while ((line = br.readLine()) != null) { if (line.startsWith("abc")) { // Do something } }
But if the first line of the file is "abcd", it won't match. By debugging I've found out that the first character is a 0 (non-printable character), and because of this it won't match. Why is that so? How could I robustly identify which lines start with "abc"?
EDIT: perhaps I should point out that I'm creating the file using notepad