【问题标题】:PHP file_get_contents in Go lang [duplicate]Go lang中的PHP file_get_contents [重复]
【发布时间】:2014-09-25 08:20:51
【问题描述】:

我是 Golang 的新手。其实我是一个PHP开发者。

我需要 Golang 中的 file_get_contents 函数。

您能否为此提供代码或根据我的要求建议 Golang 库。

注意:请记住,file-get-contents 不仅仅是“读取文件”。

【问题讨论】:

标签: php go file-get-contents


【解决方案1】:

我认为没有一个独特的 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))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-09
    • 2013-06-12
    • 2013-05-08
    • 2016-03-11
    • 1970-01-01
    • 1970-01-01
    • 2015-08-18
    相关资源
    最近更新 更多