title: How to find total number of tabs and single space characters from a file in java?
body: <p>I have been trying to find the total number of tabs and single space characters with using the code below. So if i use this </p>
  
  <pre><code>if (c[i] == '\t') {
                          ++tabcount;
                      }
  </code></pre>
  
  <p>it gives tabCount = 0, also if i want to get number of single space characters using this</p>
  
  <pre><code>if (c[i] == ' ') {
                          ++singlescpacecount;
                   }
  </code></pre>
  
  <p>it gives total number of white spaces in the whole file.</p>
  
  <p>Code for tabCount is </p>
  
  <pre><code>public static void TabCount(String filename) throws IOException{
          int tabcount = 0;
          InputStream is = new BufferedInputStream(new FileInputStream(filename));
          try {
              byte[] c = new byte[1024];
  
              int readChars = 0;
              while ((readChars = is.read(c)) != -1) {
                  for (int i = 0; i &lt; readChars; ++i) {
                      if (c[i] == '\t') {
                          ++tabcount;
                      }
  
                  }
              }
              System.out.println("The total number of tabcounts are :" + tabcount);
          } finally {
              is.close();
          }
      }
  </code></pre>
  
  <p>Thanks in advance.</p>