运用 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. Hexo瞎折腾系列(8) - 添加评论系统

    前言 Hexo的NexT主题本身就集成了一些评论系统,多说啊之类的已经关闭服务的略过不提,目前比较多人用的有畅言.来必力livere.Gitment.Gitalk.Disqus等. 我刚用的评论系统的 ...

  2. 递归遍历树形json

    前置知识: 1.首先 js里面“万物皆对象” 2.递归:自己调用自己(递归的优缺点:https://www.cnblogs.com/tchjs/p/4428153.html  https://www. ...

  3. HDU-2767-ProvingEquivalences

    链接:https://vjudge.net/problem/HDU-2767 题意: 给一个图,求最少需要几条边将其连成一个强连通图 思路: tarjan,缩点,考虑缩点后的图,出度为0的点和入度为0 ...

  4. Codeforces 1168A(二分check)

    关键是check.要注意到其实有了mid以后每个位置都是独立的,它能从哪走到哪是固定了的,只要从左到右尽量贪心压着最小值即可. #include <cstdio> const int ma ...

  5. D. Array Division

    http://codeforces.com/contest/808/problem/D 一开始是没什么想法的,然后回顾下自己想题的思路,慢慢就想出来了.首先要找到是否有这样的一个位置使得: 前缀和 = ...

  6. leecode-39. Combination Sum

    1.问题描述: Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all ...

  7. 【转】"超时时间已到。在操作完成之前超时时间已过或服务器未响应"的解决方法

    方法有以下三种: 1.原因应该在数据访问有问题,可以把连接时间设置长些,在数据库连接字符串,加上Connect Timeout=18000,单位毫秒 2,在web.config中加上以下语句: < ...

  8. Model中的验证规则

    一.能够使用Model的Attribute进行服务端数据验证 本文目录 一.概述 二.MVC提供的常用上下文 三.自定义正则表达式验证 一.概述 为了确保数据的安全性,由Client发送到服务端的每一 ...

  9. HandlerMapping执行过程。。。

    1.web.xml DispatcherServlet 类 寻址 doDispatch() 2.getHandler(requset) 点击,进入 3.HandlerMapping hm=xxxxxx ...

  10. 关于office转换成pdf组件服务中的DCOM配置问题

    在开始->运行 中录入“dcomcnfg” 单击“确定”后弹出“组件服务”窗口 依次选择“组件服务”->“计算机”->“我的电脑”->“DCOM配置” 在“DCOM配置”下找到 ...