Reputation: 11
I am trying to read strings from a text file that looks like this:
# hello my name is captain
1111 $3340 4
1211 $9182 5
1211 $9192 9
if(!line.startsWith("#")) {
System.out.println(line);
}
This prints out everything except the #
:
hello my name is captain
1111 $3340 4
1211 $9182 5
1211 $9192 9
I cant find any examples that use the !
symbol and cant tell what I'm doing wrong.
Upvotes: 1
Views: 154
Reputation: 11950
Try this. The error in your code contains a space before the comments. So check trimming it.
BufferedReader reader = new BufferedReader(new FileReader(new File("path-to-file")));
String line;
while ((line = reader.readLine()) != null){
if (!line.trim().startsWith("#")){
System.out.println(line);
}
}
Upvotes: 1