How do i skip comments with buffer reader?
<p>I have written the following program to read from a file and skip comments, it works for single line comments, but not for multi line ones. Does anyone know why? I don't need to worry about "//" in Strings. And only java comments ie "//" and "/*     */"</p>

<p>code:</p>

<pre><code>import java.io.*;

public class IfCounter2 
{   
    public static boolean lineAComment(String line)
    {
        if (line.contains("//"))    
            return true;

        return false;
    }

    public static boolean multiLineCommentStart(String line)
    {
        if (line.contains("/*"))    
            return true;

        return false;
    }

    public static boolean multiLineCommentEnd(String line)
    {
        if (line.contains("*/"))    
            return true;

        return false;
    }

    public static void main(String[] args) throws IOException 
    {
        String fileName = args[0];

        int numArgs = args.length;

        int ifCount = 0;

        // create a new BufferReader
        BufferedReader reader = new BufferedReader(new FileReader(fileName));
        String line = null;
        StringBuilder stringBuilder = new StringBuilder();
        String ls = System.getProperty("line.separator");

        line = reader.readLine();
        // read from the text file
        boolean multiLineComment = false;

        while (( line = reader.readLine()) != null) 
        {
          if (!multiLineCommentStart(line)) 
          {
            multiLineComment = true;
          }

          if (multiLineComment) {
            if (!multiLineCommentEnd(line)) 
            {
              multiLineComment = false;
            }
          }

          if (!lineAComment(line) &amp;&amp; !multiLineComment) 
          {
            stringBuilder.append(line);
            stringBuilder.append(ls);
          }
        }


        // create a new string with stringBuilder data
        String tempString = stringBuilder.toString();
        System.out.println(stringBuilder.toString());

    } 
} 
</code></pre>
