Skip to content

Commit

Permalink
read from a file
Browse files Browse the repository at this point in the history
  • Loading branch information
Kashif Jamil committed Mar 23, 2024
1 parent a5c91c5 commit e4ee3f6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
3 changes: 3 additions & 0 deletions fileRead/file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
hello, read this
print this
end of file
24 changes: 24 additions & 0 deletions fileRead/fileRead.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fileread

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

func ReadFromFile(filePath string) string {
inputFile, err := os.Open(filePath)
if err != nil {
return "error, is file exist"
}
defer inputFile.Close()
inputReader := bufio.NewReader(inputFile)
for {
inputString, readError := inputReader.ReadString('\n')
fmt.Println(inputString)
if readError == io.EOF {
return "file read ended"
}
}
}
9 changes: 3 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ package main

import (
"fmt"
lcslength "goPractice/LCSLength"
fileread "goPractice/fileRead"
)

func main() {
m := "www.educative.io/exploreeeejasdg"
n := "educative.io/edpressoooaasd,hao"
// m = "ababczb"
// n = "bababz"
fmt.Println(lcslength.LengthOfLCS(m, n))
output := fileread.ReadFromFile("/Users/mishipay/Documents/goPractice/fileRead/file.txt")
fmt.Println(output)
}

0 comments on commit e4ee3f6

Please sign in to comment.