运用 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. oracle rownum(转)

    对于Oracle的rownum问题,很多资料都说不支持>,>=,=,between……and,只能用以上符号(<.& lt;=.!=),并非说用>,>=,=,be ...

  2. LDAP第三天 MySQL+LDAP 安装

    https://www.easysoft.com/applications/openldap/back-sql-odbc.html      OpenLDAP 使用 SQLServer 和 Oracl ...

  3. 页面出现滚动条时,body里面的内容不能自动居中?

    弹窗后允许页面滚动 这种方式通常使用 position: absolute; ,可以看看我做的这个 Demo.主要用来应对弹窗内容很大很多的情况,超过了屏幕的宽高需要产生滚动条来方便浏览者查看.有一些 ...

  4. linux查看系统版本(适用于centos、ubutun,其他类型没有进行测试)

    方法一:cat /etc/issue 或more /etc/issue root@salt-master:~# cat /etc/issueUbuntu 16.04.2 LTS \n \l 方法二:l ...

  5. C/C++<算法>进制转换超详细

    16转10 用竖式计算: 16进制数的第0位的权值为16的0次方,第1位的权值为16的1次方,第2位的权值为16的2次方 第0位: 5 * 16^0 = 5 第1位: F * 16^1 = 240 第 ...

  6. 4.高级数据过滤 ---SQL

    一.AND操作符 要通过不止一个列进行过滤,可以使用A ND操作符给WHERE子句附加条件. SELECT prod_id, prod_price, prod_name FROM Products ; ...

  7. CSS样式之操作属性二

    ********css样式之属性操作******** 一.文本属性 1.text-align:cnter 文本居中 2.line heigth 垂直居中 :行高,和高度对应 3.vertical-al ...

  8. 二开获取yigo设计器里查询集合里中的某个SQL

    package com.bokesoft.lrp_v3.mid.dongming.service; import java.math.BigDecimal; import java.util.Arra ...

  9. TDH-ssh免密登录

    [root@tw-node118 ~]# ssh-keygen -t rsa -P '' 这个指令会在/root/.ssh下生成id_rsa和id_rsa.pub文件.看一下/root/.ssh下的文 ...

  10. NPOI读写Excel【转载】

    参考示例:https://www.cnblogs.com/luxiaoxun/p/3374992.html 感谢! 1.整个Excel表格叫做工作表:WorkBook(工作薄),包含的叫页(工作表): ...