使用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. 【Excel】去空格

    TRIM(TEXT) 不好用的话,把格式换成

  2. Spring Cloud微服务安全实战_3-2_第一个API及注入攻击防护

    1,本节主要讲了sql注入防范,如果使用mybatis,需要注意mapper.xml里面$会造成sql注入风险. 第一个 api 代码:https://github.com/lhy1234/sprin ...

  3. 非vue等框架中html 中使用es6的模块用法小结

    以下是html中使用es6模块化引入的方法 一.html中的引入 <!DOCTYPE html> <html lang="en"> <head> ...

  4. 使用Python3进行AES加密和解密 输入的数据

    高级加密标准(英语:Advanced Encryption Standard,缩写:AES),在密码学中又称Rijndael加密法,是美国联邦政府采用的一种区块加密标准.这个标准用来替代原先的DES, ...

  5. LOJ2507 CEOI2011 Matching

    题目链接 参考了 神仙yyb的博客 现在发现kmp不仅能匹配字符串,还可以用于处理任意模式匹配中的状态,如这题中已经匹配的序列中的数的大小关系就是一种状态,使用kmp找到模式序列的每一个前缀的bord ...

  6. vue+Element 表格编辑

    先上效果 <template> <div> <el-table :data="tableData" style="width: 100%&q ...

  7. USB、UART、SPI等总线速率(转)

    1. USB总线 USB1.1: ——-低速模式(low speed):1.5Mbps ——-全速模式(full speed): 12Mbps USB2.0:向下兼容.增加了高速模式,最大速率480M ...

  8. 转 史上最详细的Hadoop环境搭建

    GitChat 作者:鸣宇淳 原文:史上最详细的Hadoop环境搭建 关注公众号:GitChat 技术杂谈,一本正经的讲技术 [不要错过文末活动哦] 前言 Hadoop在大数据技术体系中的地位至关重要 ...

  9. Golang(三)Goroutine原理

    前言 最近用到了一些 Golang 异步编程的地方,感觉 Golang 相对于其他语言(如 Java)对多线程编程的支持非常大,使用起来也非常方便.于是决定了解一下 Goroutine 的底层原理. ...

  10. python虚拟环境切换无效问题

    使用pycharm创建新项目,使用虚拟环境,但是进入到项目的cainiao_guoguo_health\venv\Scripts目录启动虚拟环境后,安装第三方库,却还是安装到其他环境中去了, 检查ac ...