open abc.txt: The system cannot find the file specified
使用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的更多相关文章
- System.IO中的File、FileInfo、Directory与DirectoryInfo类(实例讲解)
一.建立的文件夹(对这些文件进行以上四个类的操作): 父目录: 父目录的子目录以及父目录下的文件: 子目录下的文件: 二.效果图 三.代码实现 using System; using System.I ...
- SD卡读写之FileNotFoundException: /storage/emulated/0object.txt: open failed: ENOENT (No such file or dir
读写sd卡中的文件依照例如以下步骤:1调用Environment的getExternalStorageState()方法推断手机上是否插入了sd卡.而且应用程序具有读写SD卡的能力 //假设手机已经插 ...
- The system cannot find the file specified
在家工作,程序在家里的电脑运行时,出现一个异常,还是第一见到: Server Error in '/' Application. The system cannot find the file spe ...
- ERROR: “System.Web.Mvc.Controller.File(string, string, string)”是一个“方法”
ERROR: “System.Web.Mvc.Controller.File(string, string, string)”是一个“方法”,这在给定的上下文中无效 这是一个与Controller.F ...
- Unable to chmod /system/build.prop.: Read-only file system
Unable to chmod /system/build.prop.: Read-only file system 只读文件系统 所以需要更改 使用下面的命令 mount -o remount,rw ...
- 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_ ...
- 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. ...
- 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 ...
- 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 ...
随机推荐
- 实现js版StringBuilder
.net中StringBuilder的好处不多说了,下面是js版的StringBuilder var StringBuilder = (function () { function StringBui ...
- 某模拟赛C题 树上路径统计 (点分治)
题意 给定一棵有n个节点的无根树,树上的每个点有一个非负整数点权.定义一条路径的价值为路径上的点权和-路径上的点权最大值. 给定参数P,我!=们想知道,有多少不同的树上简单路径,满足它的价值恰好是P的 ...
- 【洛谷P3835】 【模板】可持久化平衡树
可持久化非旋转treap,真的是又好写又好调 ~ code: #include <cstdio> #include <cstdlib> #include <algorit ...
- yugabyte 安装pg_hashids 扩展
主要目的比较简单,就是测试下yugabyte 对于pg 扩展的支持,今天在测试plv8的时候发现有问题(以及提交issue了,很期待官方的解决) 所以测试下一个其他的扩展,看看是否像官方介绍的那样 环 ...
- 剑指offer 6:链表(从头到尾打印链表)
链表的数据结构 struct ListNode { int value; ListNode* next; }; 那么在链表的末尾添加一个节点的代码如下: void insert(ListNode** ...
- jedis代码操作
一.jedis快速入门 * Jedis: 一款java操作redis数据库的工具. * 使用步骤: 1. 下载jedis的jar包 2. 使用 //1. 获取连接 Jedis jedis = new ...
- Spring Boot进阶系列二
上一篇文章,主要分析了怎么建立一个Restful web service,系列二主要创建一个H5静态页面使用ajax请求数据,功能主要有添加一本书,请求所有书并且按照Id降序排列,以及查看,删除一本书 ...
- AI保存文件出现了未知错误 (Adobe Illustrator)
可能的原因如下:1 把文件中所有的文字全选,转成曲线,把所有的文字都创建成轮廓2 新建一个页面,把制作的复制到新页面里3 需要把图层全部解锁再保存4 没有权限,设置一下即可5 PRINT SPOOLE ...
- linux下ELK搭建好之后配置sentinl插件,进行邮件告警
ELK的环境搭建好之后,如何利用收集到的数据进行数据告警呢?在破解ELK之后,它本身提供一个监视器功能,配置偏向编写脚本.有一个更加方便的插件sentiel. 一.下载并安装sentinl插件 htt ...
- Stateless是一个基于C#创建状态机的简单库
Stateless是一个基于C#创建状态机的简单库 .Net轻量状态机Stateless 很多业务系统开发中,不可避免的会出现状态变化,通常采用的情形可能是使用工作流去完成,但是对于简单场景下,用工作 ...