Why Doesn't This Java Code Skip Lines with #?

Posted by Nathan on Stack Overflow See other posts from Stack Overflow or by Nathan
Published on 2011-01-13T08:37:29Z Indexed on 2011/01/13 8:53 UTC
Read the original article Hit count: 216

Filed under:
|

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);
            }

© Stack Overflow or respective owner

Related posts about java

Related posts about file-io