Reading Files
来源:互联网 发布:每日工作计划软件 编辑:程序博客网 时间:2024/04/30 15:24
packagemain
import (
"bufio"
"fmt"
"io"
"io/ioutil"
"os"
)
func check(e error) {
if e != nil {
panic(e)
}
}
func main() {
dat, err := ioutil.ReadFile("/tmp/dat")
check(err)
fmt.Print(string(dat))
f, err := os.Open("/tmp/dat")
check(err)
b1 := make([]byte, 5)
n1, err := f.Read(b1)
check(err)
fmt.Printf("%d bytes: %s\n", n1, string(b1))
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))
o3, err := f.Seek(6, 0)
check(err)
b3 := make([]byte, 2)
n3, err := io.ReadAtLeast(f, b3, 2)
check(err)
fmt.Printf("%d bytes @ %d: %s\n", n3, o3, string(b3))
_, err = f.Seek(0, 0)
check(err)
r4 := bufio.NewReader(f)
b4, err := r4.Peek(5)
check(err)
fmt.Printf("5 bytes:%s\n", string(b4))
f.Close()
}
0 0
- Reading Files
- Reading Files
- Reading and Writing Files
- Class for reading INI files
- Reading and writing text files
- Reading Excel files using ODBC
- 1.7writing and reading files
- Reading and writing text files
- Reading and writing binary files
- Reading and writing text files
- reading and writing xml files
- Reading files-读取文件内容
- Reading Excel (.xls) Files with ADO.NET...
- Reading and Writing to Binary Files
- Reading and writing .mat files with Python
- [LUA学习笔记]Reading Configuration Files
- Reading and Writing CSV Files in MFC
- Reading and Writing Perl Config Files
- 溯源之梦回秦淮
- source insight打不开
- 北美IT公司大致分档
- 吴晓波领衔“大头频道”音频版独家入驻喜马拉雅FM意欲何为?
- 设置mysql允许外部IP访问
- Reading Files
- 灵境
- MyCat - 使用篇(1)
- iOS开源库大集合
- 数据保护API
- 心然-心之所在,浮生安然
- iOSCoreAnimation CABasicAnimation 详解
- C++开发ActiveX控件相关
- OpenGL-tutorials之射线求交选择(Picking with custom Ray-OBB function)