public static long countRows(Configuration conf, byte[] tableName) throws IOException {
        HTable hTable = null;
        ResultScanner rs = null;
        long count = 0;
        try {
            hTable = new HTable(conf, tableName);
            rs = hTable.getScanner(new Scan());
            for(@SuppressWarnings("unused") Result r: rs) {
                count++;
            }
            return count;
        } finally {
            if(hTable != null) {
                hTable.close();
            }
            if(rs != null) {
                rs.close();
            }
        }
    }
public static long countRows ( Configuration conf , byte [ ] tableName ) throws IOException { HTable hTable = null ; ResultScanner rs = null ; long count = 0 ; try { hTable = new HTable ( conf , tableName ) ; rs = hTable . getScanner ( new Scan ( ) ) ; for ( @ SuppressWarnings ( "unused" ) Result r : rs ) { count ++ ; } return count ; } finally { if ( hTable != null ) { hTable . close ( ) ; } if ( rs != null ) { rs . close ( ) ; } } }
Only use this for testing/debugging. Inefficient.