How Can I Find Out The Number Of Empty Line On File


I want to find empty line on file
Favorman.txt contains

First Line: Hello
Second Line: // Empty Line
Third Line : Everybody
Fourth Line : // Empty Line
Fifth Line : Its me

How can I find out the number of empty lines


First line
Second line
Third line

Third line

Third line

Third line

Third line

Third line

Third line


package main

import (

func main() {
	fileIO, err := os.OpenFile("arquivo.txt", os.O_RDWR, 0600)
	if err != nil {
	defer fileIO.Close()
	rawBytes, err := ioutil.ReadAll(fileIO)
	if err != nil {
	countLines := 0
	lines := strings.Split(string(rawBytes), "\n")
	for _, line := range lines {
		if line == "" {
			countLines += 1
	fmt.Println("Total: " + strconv.Itoa(countLines))

Again thanks , you are my hero:)

we’re welcome, :slight_smile:

I noticed that you also posted this same question to golang-nuts after receiving your answer here. This is considered poor etiquette. Please try not to do this in the future.

1 Like

They are not same questions . Look at one more times before you judge me.!topic/golang-nuts/ZrlDjqkxcWs

Is this your question?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.