当前位置:网站首页>NodeJS(四) 字符读取
NodeJS(四) 字符读取
2022-04-23 06:27:00 【老少年】
console.log("ssss");
var fs=require("fs");
var re=fs.createReadStream("Test.txt",{highWaterMark:7});
re.setEncoding('utf8');
var texts="";
re.on("data",function(chunk){
texts+=chunk;
});
re.on("end",function(){
console.log(texts);
});
console.log("5555");
1.当读取数据时编译方式不同,会出现乱码,re.setEncoding('utf8');指定编码的方式可以避免问题
var fs=require("fs");
var re=fs.createReadStream("Test.txt",{highWaterMark:7});
var xxx=[];
var size=0;
re.on("data",function(chunk){
xxx.push(chunk);
size += chunk.length;
});
re.on("end",function(){
var text=Buffer.concat(xxx,size);
console.log(text.toString());
});
console.log("5555");
2.读取数据时可以先缓存下来,最后拼接
版权声明
本文为[老少年]所创,转载请带上原文链接,感谢
https://blog.csdn.net/laoshaonian/article/details/103162408
边栏推荐
- 将指定路径下的所有SVG文件导出成PNG等格式的图片(缩略图或原图大小)
- [Ted series] how does a habit change my life
- 手游的热更方案与动态更新策略
- Solutions to common problems in visualization (VII) solutions to drawing scale setting
- 系统与软件安全研究(四)
- Nacos / sentinel gateway current limiting and grouping (code)
- js之作用域、作用域链、全局变量和局部变量
- 二叉树的深度
- Judge whether the beginning and end of the string contain target parameters: startswith() and endswith() methods
- 2022.3.14 Ali written examination
猜你喜欢
Custom time format (yyyy-mm-dd HH: mm: SS week x)
设置了body的最大宽度,但是为什么body的背景颜色还铺满整个页面?
ABAP 从CDS VIEW 发布OData Service示例
The page displays the current time in real time
'NPM' is not an internal or external command, nor is it a runnable program or batch file
Install and configure Taobao image NPM (cnpm)
中间人环境mitmproxy搭建
将指定路径下的所有SVG文件导出成PNG等格式的图片(缩略图或原图大小)
SAP PI/PO Soap2Proxy 消费外部ws示例
基于NLP的软件安全研究(二)
随机推荐
Nacos / sentinel gateway current limiting and grouping (code)
Mobile game performance optimization
二叉树的深度
2022.3.14 阿里笔试
Page dynamic display time (upgraded version)
canvas学习第一篇
简易随机点名抽奖(js下编写)
ABAP 从CDS VIEW 发布OData Service示例
超级宝典&编程指南(红蓝宝书)-读书笔记
SAP PI/PO rfc2RESTful 發布rfc接口為RESTful示例(Proxy間接法)
SAP PI/PO rfc2RESTful 发布rfc接口为RESTful示例(Proxy间接法)
h5本地存储数据sessionStorage、localStorage
移动布局(flex布局、视口标签)
Authorization server (simple construction of authorization server)
驼峰命名对像
How to judge whether a point is within a polygon (including complex polygons or a large number of polygons)
C# 文本文件的查找及替换(WinForm)
9.常用函数
js之DOM学习获取元素
typescript字典的使用