Why Doesn't This Java Code Skip Lines with #?
- by Nathan
I'm trying to allow an external .txt file that is read by a Java script be able to have some comments in the beginning of the file so others can easily edit it and add more to it.
But if the file contains # (the sign designated for a line that is a comment) it just returns the error that there is a "Format Error in file" (the IOException - so it is getting past that first "IF"...)
Can someone help?
Here's the portion of the code that deals with commenting lines out of the .txt file being called earlier in the script:
while ((line = br.readLine()) != null) {
line = line.trim();
if (line.length() < 1 || line.charAt(0) == '#') { // ignore comments
continue;
}
final String[] parts = line.split("=");
if (parts.length != 2) {
throw new IOException("Format error in file "
+ JLanguageTool.getDataBroker().getFromRulesDirAsUrl(getFileName())
+ ", line: " + line);
}