运用 ioutil.ReadFile 、ioutil.WriteFile

package main

import (
"io/ioutil"
"log"
"os"
) func main() { buf, err := ioutil.ReadFile("C:/文档/MHOSO/conf/conf.txt")
if err != nil {
log.Println(err)
}
log.Println(string(buf))
log.Println() //buf.append('8')
/*newBuf := make([]byte, len(buf)*5)
copy(newBuf, buf)
log.Println(string(newBuf))
log.Println()
buf = newBuf*/ str := []byte("this is the new word")
log.Println(string(str))
log.Println() buf = append(buf, str...)
//buf := []byte("hi this is test")
ioutil.WriteFile("C:/文档/MHOSO/conf/conf.txt", buf, os.ModeAppend)
log.Println(string(buf))
}

*** 输出结果比较奇怪,不知道是不是内存问题:

[Running] go run "c:\Users\cjige\Desktop\test.go"
2018/12/03 20:50:11 hi this is test2018/12/03 20:50:11 hi this is test
[Done] exited with code=0 in 1.647 seconds

更换文件位置后,测试结果如下,append没有成功

[Running] go run "c:\文档\Go\学习\文件读写.go"
2018/12/03 20:54:17 hi this is test2018/12/03 20:54:17
2018/12/03 20:54:17 this is the new word
2018/12/03 20:54:17
2018/12/03 20:54:17 hi this is test
[Done] exited with code=0 in 1.542 seconds

Golang ioutil读写文件测试的更多相关文章

  1. 002-Go通过ioutil 读写文件

    1.读取文件内容 package main import( "io/ioutil" "fmt" ) func main(){ b,err := ioutil.R ...

  2. golang的写文件测试

    package main import ( "os" "strings" "time" "fmt" "strc ...

  3. 转:Java读写文件各种方法及性能比较

    干Java这么久,一直在做WEB相关的项目,一些基础类差不多都已经忘记.经常想得捡起,但总是因为一些原因,不能如愿. 其实不是没有时间,只是有些时候疲于总结,今得空,下定决心将丢掉的都给捡起来. 文件 ...

  4. golang bufio、ioutil读文件的速度比较(性能测试)和影响因素分析

    前言 golang读取文件的方式主要有4种: 使用File自带的Read方法 使用bufio库的Read方法 使用io/ioutil库的ReadAll() 使用io/ioutil库的ReadFile( ...

  5. golang读写文件

    1. 标准输入输出 os提供了标准输入输出文件: Stdin = NewFile(uintptr(syscall.Stdin), "/dev/stdin") Stdout = Ne ...

  6. golang读写文件的几种方式

    golang中处理文件有很多种方式,下面我们来看看. (1)使用os模块 先来看看如何查看文件属性 package main import ( "fmt" "os&quo ...

  7. golang学习笔记 ----读写文件

    使用io/ioutil进行读写文件 ioutil包 其中提到了两个方法: func ReadFile func ReadFile(filename string) ([]byte, error) Re ...

  8. 使用io/ioutil进行读写文件

    读文件: package main import ( "fmt" "io/ioutil" ) func main() { b, err := ioutil.Re ...

  9. Go标准库之读写文件(File)

    Go标准库之读写文件(File) 创建一个空文件 package main import ( "log" "os" ) func main() { file, ...

随机推荐

  1. 解决phpwind 9 转换到 discuz x 3.1的头像仍然不显示问题

    phpwind 9 转换到 discuz x 3.1后,按照discuz转换程序的步骤做,头像仍然不显示,后来登录后重新上传头像发现,是文件名的原因,如下操作改名即可(还好我的论坛会员不多,不然手改累 ...

  2. Windows右下角图标显示不正常

    我的win7系统,右下角图标透明,分不清哪个是哪个.点击也没有任何反应. 解决办法: 点击运行输入cmd,在命令提示符下输入下列命令即可恢复. taskkill /im explorer.exe /f ...

  3. std::less

    std::less   定义于头文件 <functional>     template< class T >struct less;   (C++14 前) template ...

  4. 1.检索数据 ---SQL

    相关提示: 结束SQL语句 多条SQL语句必须以分号(:)分隔.多数DBMS不需要在单条SQL语句后加分号,但也有DBMS可能必须在单条SQL语句后加上分号.当然,如果愿意可以总是加上分号.事实上,即 ...

  5. fstream类总结

    - ofstream, ifstream, fstream 在头文件fstream中,在fstream类中,用open成员函数打开文件,实现类与文件的关联操作. - open(filename, mo ...

  6. CodeForces - 581B-Luxurious Houses

    The capital of Berland has n multifloor buildings. The architect who built up the capital was very c ...

  7. 不可见类有抽象父类,spring配置子类bean,注入父类,aop就可以切父类的方法

    public class TestBeanChild { int b = 1; public TestBean createDefault() { return new TestBeanDefault ...

  8. centos虚拟机安装指定版本docker

    环境: centos 7.6+ docker-ce 17.03.2 安装依赖包 yum -y install yum-utils device-mapper-persistent-data lvm2 ...

  9. Linux清空屏幕和清空当前输入的快捷键

    Linux清空屏幕和清空当前输入的快捷键 但是实际上...放弃当前的命令,命令行提示符跳到下一行的有效命令是ctrl + c

  10. Joda-Time简介

    Joda-Time提供了一组Java类包用于处理包括ISO8601标准在内的date和time.可以利用它把JDK Date和Calendar类完全替换掉,而且仍然能够提供很好的集成. Joda-Ti ...