nodejs 文件操作
来源:互联网 发布:易通网络加速器官网 编辑:程序博客网 时间:2024/06/05 10:45
/** * Created by 26223 on 2016/11/8. */const fs = require('fs');const FileUtils = exports;//写入文件FileUtils.writeFile = function (filePath,data) { fs.writeFile(filePath, data, function (err) { if (err) throw err; console.log('file save successfully '); //文件被保存 });};//读取FileUtils.readFile = function(filePath,encoding){ let length = arguments.length; if(length<2){ encoding = 'utf-8' } fs.readFile(filePath, encoding, function (err, data) { if (err) throw err; console.log(data); });};//复制FileUtils.copyFile = function (srcFile,newFile) { let readOption = { flags : 'r', encoding : null, mode : 0o666 }; let writeOption = { flags: 'a', encoding: null, mode: 0o666 }; let fileReadStream = fs.createReadStream(srcFile,readOption); let fileWriteStream = fs.createWriteStream(newFile,writeOption); /* 1: fileReadStream.on('data',function(data){ fileWriteStream.write(data); }); fileReadStream.on('end',function(){ console.log('readStream end'); fileWriteStream.end(); }); */ /** * 2: */ fileReadStream.pipe(fileWriteStream); fileWriteStream.on('close',function(){ console.log('copy over'); });};var result=JSON.parse(fs.readFileSync('config.json'));console.info(result);// FileUtils.copyFile('./PageHelper.js','./newPageHelper.js');
0 0
- nodejs文件操作
- nodejs文件操作
- nodejs 文件操作笔记
- nodejs之文件操作
- NodeJs文件操作备注
- nodejs 文件操作
- nodejs文件流操作
- nodejs文件操作
- nodejs 文件操作
- nodejs用流来对文件操作
- NodeJS操作文件相关总结
- nodejs 操作文件(文件夹)
- NodeJS入门(3)-文件操作
- nodejs 服务器创建及文件读写操作
- nodejs对文件操作的api
- nodejs-操作文件系统读取写入文件
- 重拾nodejs之文件操作
- Nodejs笔记(4)——文件操作
- 线程安全的集合类
- MySQL性能优化总结
- MySQL技术内幕 InnoDB存储引擎(一)
- Java多线程之并发工具类之CyclicBarrier
- mac mobile angular ui安装
- nodejs 文件操作
- JAVA修饰词详解:public、protected、default、private
- JAVA设计模式(原型模式)
- ssm sql 例子(freemarker+jsp)
- 码农成长记——css之背景与边框
- Android Studio Problems
- malloc函数实现原理
- javascript事件——事件处理程序
- 1的数量(51nod)