Java File Read by Charset getNumberOfNonEmptyLines(File file, Charset charset)

Here you can find the source of getNumberOfNonEmptyLines(File file, Charset charset)

Description

get Number Of Non Empty Lines

License

LGPL

Declaration

public static int getNumberOfNonEmptyLines(File file, Charset charset) throws IOException 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

import java.nio.charset.Charset;

public class Main {
    public static int getNumberOfNonEmptyLines(File file, Charset charset) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), charset));
        try {/*www  .  j  av a2s. c o m*/
            int count = 0;
            String line;
            while ((line = reader.readLine()) != null)
                if (!line.isEmpty())
                    ++count;
            return count;
        } finally {
            reader.close();
        }
    }
}

Related

  1. getEOL(File file, Charset charset)
  2. getFileContent(File file, String charsetName)
  3. getFileContents(File file, String charset)
  4. getFileEncodingCharset()
  5. getFileText(File file, Charset charset)
  6. getPatchFileCharset()
  7. getPropertiesVaule(File file, String key, Charset charset)
  8. getString(File file, Charset charset)
  9. getUncommentedLines(File file, Charset forName)