Count number of lines in a file

@param filename
@return
@throws IOException
975917
public static int countLines(String filename) throws IOException {
        FileInputStream fis = new FileInputStream(filename);
        try {
            return countLines(new BufferedInputStream(fis));
        } finally {
            fis.close();
        }
    }
611844
private function countFiles($fieldName = null)
    {
        $finder = new Finder();
        $finder->files()->in($this->getFilePath($fieldName));
        return count($finder);
    }
788893
public int getNumberOfBlocks(final FileStatus file) throws IOException {

		int numberOfBlocks = 0;

		if (file == null) {
			return 0;
		}

		// For a file, this is easy
		if (!file.isDir()) {
			return getNumberOfBlocks(file.getLen(), file.getBlockSize());
		}

		// file is a directory
		final FileStatus[] files = this.listStatus(file.getPath());
		for (int i = 0; i < files.length; i++) {

			if (!files[i].isDir()) {
				numberOfBlocks += getNumberOfBlocks(files[i].getLen(), files[i].getBlockSize());
			}
		}

		return numberOfBlocks;
	}
1312905
public boolean add(String fileName) {
      writeLock.lock();
      try {
         return filenames.add(fileName);
      } finally {
         writeLock.unlock();
      }
   }
1178577
public void addPrefixesFile(String filename) throws IOException {
    try (Reader r = Files.newBufferedReader(Paths.get(filename), StandardCharsets.UTF_8)) {
      addPrefixProperties(r);
    }
  }
135258
def count_lines(abspath):
    
    with open(abspath, "rb") as f:
        i = 0
        for line in f:
            i += 1
            pass
        return i
913592
public static List<String> linesFromFile(String filename,String encoding) {
    try {
      List<String> lines = new ArrayList<String>();
      BufferedReader in = new BufferedReader(new EncodingFileReader(filename,encoding));
      String line;
      while ((line = in.readLine()) != null) {
        lines.add(line);
      }
      in.close();
      return lines;
    }
    catch (IOException e) {
      e.printStackTrace();
      return null;
    }
  }
691939
public static String readFile(String fileName) throws IOException {
        logger.entering(fileName);
        Preconditions.checkArgument(StringUtils.isNotBlank(fileName), "File name cannot be null (or) empty.");
        StringBuilder output = new StringBuilder();
        try (BufferedReader buffreader = new BufferedReader(new InputStreamReader(loadFile(fileName),
                Charset.forName("UTF-8")))) {
            String line = null;
            while ((line = buffreader.readLine()) != null) {
                output.append(line);
            }
        }
        logger.exiting(output);
        return output.toString();
    }
1245385
def count_lines(path, extensions=None, excluded_dirnames=None):
    """"""
    if extensions is None:
        extensions = ['.py', '.pyw', '.ipy', '.enaml', '.c', '.h', '.cpp',
                      '.hpp', '.inc', '.', '.hh', '.hxx', '.cc', '.cxx',
                      '.cl', '.f', '.for', '.f77', '.f90', '.f95', '.f2k',
                      '.f03', '.f08']
    if excluded_dirnames is None:
        excluded_dirnames = ['build', 'dist', '.hg', '.svn']
    def get_filelines(path):
        dfiles, dlines = 0, 0
        if osp.splitext(path)[1] in extensions:
            dfiles = 1
            with open(path, 'rb') as textfile:
                dlines = len(textfile.read().strip().splitlines())
        return dfiles, dlines
    lines = 0
    files = 0
    if osp.isdir(path):
        for dirpath, dirnames, filenames in os.walk(path):
            for d in dirnames[:]:
                if d in excluded_dirnames:
                    dirnames.remove(d)
            if excluded_dirnames is None or \
               osp.dirname(dirpath) not in excluded_dirnames:
                for fname in filenames:
                    dfiles, dlines = get_filelines(osp.join(dirpath, fname))
                    files += dfiles
                    lines += dlines
    else:
        dfiles, dlines = get_filelines(path)
        files += dfiles
        lines += dlines
    return files, lines
827243
public String read(String filename) throws IOException {
    Path p = new Path(filename);
    int size = (int) getMfs().getFileStatus(p).getLen();
    FSDataInputStream is = getMfs().open(p);
    byte[] content = new byte[size];
    is.readFully(content);
    return new String(content);
  }
1021936
public static void writeByteArrayToFile(final String filename, final byte[] byteArray)
		throws IOException
	{
		final File file = new File(filename);
		writeByteArrayToFile(file, byteArray);
	}
1112403
def count_lines(self, file_name):
        
        x = subprocess.check_output("wc -l " + file_name + " | sed -E 's/^[[:space:]]+//' | cut -f1 -d' '", shell=True)
        return x.strip()
589602
public int getNumberOfRows(final String fileName, final String sheetName)
			throws IOException {
		LOG.info("Getting the number of rows from:" + fileName + " sheet: "
				+ sheetName);
		Workbook workbook = getWorkbook(fileName);
		Sheet sheets = workbook.getSheet(sheetName);
		return sheets.getPhysicalNumberOfRows();
	}
517976
public static Reader openFileReader(final String fileName) throws IOException
	{
		BufferedReader bufferedReader = null;
		final File file = new File(fileName);
		bufferedReader = (BufferedReader)StreamExtensions.getReader(file);
		return bufferedReader;
	}
194499
public static int getLineCount(final String text) {
    final Matcher matcher = LINE_FINDER.matcher(text);
    int i = 0;

    while (matcher.find()) {
      i++;
    }

    return i;
  }
106359
public void stringToFile(String content, String filename) throws IOException {
        stringToOutputStream(content, new FileOutputStream(filename));
    }
1114753
public String readFromFile(String fileName) {
    String content = null;
    BufferedReader br = null;
    try {
      File inFile = new File(fileName);
      br = new BufferedReader(new InputStreamReader(
          new FileInputStream(inFile)));
      content = "";
      while(br.ready()) {
      	content += br.readLine();
      }
      br.close();
    } catch (FileNotFoundException ex) {
    	log.error("Failed to find file.", ex);
    } catch (IOException ex) {
    	log.error("Failed to read file.", ex);
    } finally {
    	if(br != null) {
    		try {
    			br.close();
    		} catch(Exception e){}
    	}
    }
    return content;
  }