Go lang中的PHP file_get_contents

Cha*_*kka 6 php file-get-contents go

我是Golang的新手.其实我是PHP开发人员.

我需要file_get_contentsGolang中的功能.

您可以根据我的要求为此提供代码或建议Golang库.

注意:请记住file-get-contents,不仅仅是"读取文件".

Von*_*onC 6

我不认为有一个独特的golang功能多才多艺file-get-contents.php.

您经常需要更多地控制文件的读取方式和部分.
对于这些任务,首先打开一个文件以获取os.File值.

f, err := os.Open("/tmp/dat")
check(err)

# You can also Seek to a known location in the file and Read from there.

o2, err := f.Seek(6, 0)
check(err)
b2 := make([]byte, 2)
n2, err := f.Read(b2)
check(err)
fmt.Printf("%d bytes @ %d: %s\n", n2, o2, string(b2))
Run Code Online (Sandbox Code Playgroud)