Skip to content

Commit

Permalink
Merge pull request #21 from sanjeevtripurari/master
Browse files Browse the repository at this point in the history
Example Reading file in GO
  • Loading branch information
sunny7899 authored Oct 30, 2024
2 parents 750c809 + e314ac9 commit f093a6d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions filehandling/readfile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// program to read file

package main

import (
"bufio"
"fmt"
"os"
)

func main() {
filename := os.Args[1]

readlFile, err := os.Open(filename)
if err != nil {
fmt.Printf("error openning file: %v\n", err)
os.Exit(1)
}

fileInfo, _ := os.Stat(filename)
fileName, fileSize := fileInfo.Name(), fileInfo.Size()
fmt.Printf("\nReading..\n\tFileName : %v\n\tSize : %v\n\n", fileName, fileSize)

fileScanner := bufio.NewScanner(readlFile)
fileScanner.Split(bufio.ScanLines)

for fileScanner.Scan() {
fmt.Println(fileScanner.Text())
}
readlFile.Close()
}
Binary file added filehandling/zenofgo.txt
Binary file not shown.

0 comments on commit f093a6d

Please sign in to comment.