使用io/ioutil包读取文件时报错:open abc.txt: The system cannot find the file specified

原因是:ioutil.ReadFile()这个方法需要传入决绝路径的文件名

代码:

const filename  = "E:\\GoWorks\\Golang\\src\\if\\abc.txt"
//const filename = "abc.txt" //这样写会报错
//contents, err := ioutil.ReadFile(filename) //读取文件
//if err != nil {
// fmt.Println("err=",err)
//} else {
// fmt.Printf("%s\n", contents)
//} //上面的写法可以改为:
if contents, err := ioutil.ReadFile(filename); err != nil {
fmt.Println("err=", err)
} else {
fmt.Printf("%s\n", contents)
} //注意:if的条件里可以赋值
//if的条件里赋值的变量作用域就在这个if语句里

open abc.txt: The system cannot find the file specified的更多相关文章

  1. System.IO中的File、FileInfo、Directory与DirectoryInfo类(实例讲解)

    一.建立的文件夹(对这些文件进行以上四个类的操作): 父目录: 父目录的子目录以及父目录下的文件: 子目录下的文件: 二.效果图 三.代码实现 using System; using System.I ...

  2. SD卡读写之FileNotFoundException: /storage/emulated/0object.txt: open failed: ENOENT (No such file or dir

    读写sd卡中的文件依照例如以下步骤:1调用Environment的getExternalStorageState()方法推断手机上是否插入了sd卡.而且应用程序具有读写SD卡的能力 //假设手机已经插 ...

  3. The system cannot find the file specified

    在家工作,程序在家里的电脑运行时,出现一个异常,还是第一见到: Server Error in '/' Application. The system cannot find the file spe ...

  4. ERROR: “System.Web.Mvc.Controller.File(string, string, string)”是一个“方法”

    ERROR: “System.Web.Mvc.Controller.File(string, string, string)”是一个“方法”,这在给定的上下文中无效 这是一个与Controller.F ...

  5. Unable to chmod /system/build.prop.: Read-only file system

    Unable to chmod /system/build.prop.: Read-only file system 只读文件系统 所以需要更改 使用下面的命令 mount -o remount,rw ...

  6. Docker 报错 error during connect: Get pipe/docker_engine: The system cannot find the file specified. - 摘要: 本文讲的是Docker 报错 error during connect: Get pipe/dock

    error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.37/version: open //./pipe/docker_ ...

  7. Fixed: The Windows Process Activation Service service terminated with the following error: The system cannot find the file specified

    I'm not yet clear what I did, but I'm blogging it so it can be found if someone else has this issue. ...

  8. Nginx错误:nginx: [error] OpenEvent("Global\ngx_reload_6252") failed (2: The system cannot find the file specified)

    执行nginx -s reload命令: nginx: [error] OpenEvent("Global\ngx_reload_6252") failed (2: The sys ...

  9. CMake error:System Error:No such file or directory CMake error:Could not open file for write in copy operation xxxx.ros_Config.cmake.tmp.

    微型电脑或嵌入式与电脑还是有点不同的,在微型电脑上ros indigo 版本下利用catkin编译如果你遇到如下错误: CMake error:System Error:No such file or ...

随机推荐

  1. 【oracle】ORA-00257 archiver error. Connect internal only, until freed

    [原因]归档日志太多导致磁盘空间过小. [解决办法]删除日志或加大空间

  2. MapReduce 程序mysql JDBC驱动类找不到原因及学习hadoop写入数据到Mysql数据库的方法

    报错 :ClassNotFoundException: com.mysql.jdbc.Driver 需求描述: hadoop需要动态加载个三方jar包(比如mysql JDBC 驱动包),是在MR结束 ...

  3. Linux中关于samba的几个问题

    一.用smbclient命令登录成功但看不了文件 原因:SELinux的阻挡 解决:1.关闭SELinux  :  setenforce 0   (临时生效,重启后失效) 或vi /etc/sysco ...

  4. zabbix解决监控图形中文乱码

    原文: https://blog.csdn.net/xujiamin0022016/article/details/86541783 zabbix 4解决监控图形中文乱码首先在windows里找到你想 ...

  5. 一张MGR切换的图,不解释

  6. 使用IDEA创建一个Servlet应用程序

    使用IDEA创建一个Servlet应用程序 第一步:创建web应用 选择web application应用,之后填写项目名称等. 第二步:项目配置 在WEB-INF目录下创建两个文件夹:classes ...

  7. Python【每日一问】31

    问: [基础题]:有 n 个人围成一圈,顺序排号.从第一个人开始报数(从 1 到 3 报数) ,凡报到 3 的人退出圈子,问最后留下的是原来第几号的那位. (n由键盘输入,比如n=100) [提高题] ...

  8. angualr post 数据请求

    数据请求 post 新建一个服务 1. ng g service services /+服务名  eg:ng g service services/player 在此服务中进行设置 引入自带组件以及注 ...

  9. spring 事件使用

    1.事件定义 import lombok.Data; import org.springframework.context.ApplicationEvent; /** * 事件定义,这里监听MsgMe ...

  10. 洛谷P5017:摆渡车——题解

    https://www.luogu.org/problem/P5017 参考:https://www.luogu.org/blog/ztyluogucpp/solution-p5017 我想我大概是废 ...