安装读写文件对应模块

$ npm install fs-extra -S
npm WARN saveError ENOENT: no such file or directory, open 'E:\study\ts\package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open 'E:\study\ts\package.json'
npm WARN ts No description
npm WARN ts No repository field.
npm WARN ts No README data
npm WARN ts No license field.
+ fs-extra@8.1.0
added 4 packages from 2 contributors and audited 5 packages in 15.118s
found 0 vulnerabilities
$ npm install path -S
npm WARN saveError ENOENT: no such file or directory, open 'E:\study\ts\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'E:\study\ts\package.json'
npm WARN ts No description
npm WARN ts No repository field.
npm WARN ts No README data
npm WARN ts No license field.
+ path@0.12.7
added 4 packages from 2 contributors and audited 14 packages in 13.962s
found 0 vulnerabilities

如果想在vscode中添加自动提示功能,比如添加fs-extra模块的文档,则运行

npm i @types/fs-extra

然后鼠标定位到要查找的代码上,F12就跳转过去查看文档了。happy.

写代码列出当paths目录下文件列表

import * as fs from 'fs-extra';
import * as path from 'path';
const dirPath = path.resolve(`$(__dirname)`, '../paths/');
console.log(dirPath);
fs.readdir(dirPath, function (err, files) {
    if (err) {
        return console.log("err" + err);
    files.forEach(function (f: string) {
        console.log("f-", f);

列出列表结果为:

再扩展一下,读取paths文件夹下文件的内容。

import * as fs from 'fs-extra';
import * as path from 'path';
const dirPath = path.resolve(`$(__dirname)`, '../paths/');
const outDir = path.resolve(`$(__dirname)`,'../outDir/');
console.log(dirPath);
function mkOutDir(){
function readContent(dir: string, fName: string) {
    let fPath: string = dir.concat("\\").concat(fName);
    fs.readFile(fPath, "utf8", function (err, data) {
        if (err) {
            return console.error(err);
        console.log(data);
        console.log("--------", fPath);
fs.readdir(dirPath, function (err, files) {
    if (err) {
        return console.log("err" + err);
    files.forEach(function (f: string) {
        readContent(dirPath, f);

再扩展一下,读取paths目录下的文件,处理后写到outDir目录下

import * as fs from 'fs-extra';
import * as path from 'path';
const dirPath = path.resolve(`$(__dirname)`, '../paths/');
const outDir = path.resolve(`$(__dirname)`, '../outDir/');
console.log(dirPath);
function mkOutDir() {
function num2str(num: number): string {
    let text: string = String(num);
    if (text.indexOf(".") === -1) {
        text += ".00";
    } else {
        text += "0000";
    let index: number = text.indexOf(".") + 3;
    text = text.substring(0, index);
    return text;
function dealOneFile(content: string, fName: string) {
    let sp: string[] = content.split("\n");
    if (sp.length <= 1) {
        console.error("error dealOneFile. fName = ", fName);
        process.exit(1);
    let buf: string[] = [];
    let total: number = Number(sp[0]);
    let startSec: number = total;
    for (let i: number = 1; i < sp.length; i++) {
        let text: string = sp[i];
        if (text && text.length > 0) {
            let params: string[] = text.split("|");
            let begin: number = Number(params[1]);
            if (begin < startSec) {
                startSec = begin;
    buf.push(String(total - startSec));
    for (let i: number = 1; i < sp.length; i++) {
        let text: string = sp[i];
        if (text && text.length > 0) {
            let params: string[] = text.split("|");
            let begin: number = Number(params[1]);
            let end: number = Number(params[2]);
            let bStr: string = num2str(begin - startSec);
            let eStr: string = num2str(end - startSec);
            let line: string = params[0] + "|" + bStr + "|" + eStr + "|" + params[3];
            buf.push(line);
    let fPath: string = outDir + "\\" + fName;
    fs.removeSync(fPath);
    fs.writeFileSync(fPath, buf.join("\n"));
    console.log("write fPath = ", fPath);
function readContent(dir: string, fName: string) {
    let fPath: string = dir.concat("\\").concat(fName);
    fs.readFile(fPath, "utf8", function (err, data) {
        if (err) {
            return console.error(err);
        dealOneFile(data, fName);
function dealFilesInDir() {
    fs.readdir(dirPath, function (err, files) {
        if (err) {
            return console.log("err" + err);
        files.forEach(function (f: string) {
            readContent(dirPath, f);
let isOutExist: boolean = fs.pathExistsSync(outDir);
if (!isOutExist) {
    console.log("isOutExist = ", isOutExist, ", outDir=", outDir);
    fs.mkdirsSync(outDir);
dealFilesInDir();
                                    随着各种现代浏览器、以及node对ES6的支持,已经有越来越多的ES6特性可以在程序中使用,她们给开发过程带来的便利不言而喻,举个小例子,我想从一个数组里找一些符合条件的数据,放入另一个数组内,过去我们这么写:varlist=[],i;它的基本语法为:VLOOKUP(查找目标,查找范围,返回值的列数,精确OR模糊查找)下面以一个实例来介绍一下这四个参数的使用例1:如下图所示,要求根据表二中的姓名,查找姓名所对应的年龄。8、TypeScript中引入了模块的概念,可以把声明、数据、函数和类封装在模块中。
fs.writeFileSync("./src/test.txt", "123465798")
let readf = fs.readFileSync("./src/test.txt", "utf8")
console.log(readf)
 M (备忘)注意:备忘支持是实验性/部分支持,但有以下限制:
 只读(无法创建/写入带有备注字段的DBF文件)
 仅dBase III(版本0x83)和dBase IV(版本0x8b) .dbt备忘文件
“松散”读取模式-尝试读取任何类型的.dbf文件,而不会发出抱怨。 不支持的字段类型将被跳过。
 可以打开现有的.dbf文件
可以访问所有字段描述符
可以访问总记录数
可以读取任意大小的记录
支持超大文件
可以创建一个新的.dbf文件可以使用另一个实例的用户指定对象中的字段描述符
可以将记录追加到现有的.dbf文件中支持超大文件
注意:基于浏览器的版本正在建设中。 请支持这个项目。
可以阅读和书写其语言的孩子可以学习编码。 像code.org这样的可视编程参考都支持无需键入代码。 因此,在code.org实验之后,孩子将准备进行编码。 但是,对于第一个实验,没有针对儿童的编程语言。 他们能够用其母语编写程序。 例如,要打印到屏幕上的内容是英语的“打印Hello”和土耳其语的“ yaz Merhaba”等​​。为了进行词法分析或解析,需要考虑非字母数字字符,缩进和其他标记。
 这种语言的目标是训练孩子打印和读取变量,并通过简单的if while函数实现数学运算
                                    TypeScript 是 js 类型的超集。它假设咱们知道什么是超集,什么是类型化。为了简单起见,你可以将TypeScript 看作是 JavaScript 之上的一个外壳。TypeScript 是一个外壳,因为编写 TypeScript 的代码,在编译之后,,剩下的只是简单的 js 代码。但是 JS 引擎无法读取 TypeScript 代码,因此任何 TypeScript 文件都应该经过预翻译过程,即编译。只有在第一个编译步骤之后,才剩下纯 JS 代码,可以在浏览器中运行。...
                                    <br />版权声明
:转载时请以超链接形式标明文章原始出处和作者信息及本声明<br />http://pp99nn.blogbus.com/logs/46943583.html<br /><br />javascript在浏览器本地和与服务器通讯方面都有优异的表现。<br />使用javascript对本地文件进行操作实际上是有一点技术后退的感觉。毕竟桌面应用程序微软的、java的已经相当成熟了。不过用
javascript做点小程序来处理本地事务,在没有java或者MFC开发环境的时候还是很方便的。
//读文件解析乱码
      private String readFile()throws IOException {
		String path = "C:\\Users\\jadl\\Desktop\\test.txt";
		File f = new File(path);
		FileInputStream fip = new FileInputStream(f);
		InputStreamReader reader = new Inp
二:路径设置,相对路径、绝对路径怎么引入,因为路径不正确肯定会提示找不到模块 
三:为什么 
var data = require(‘/sandbox/project/sync/name.json’) 
var tmp = JSON.parse(data); 
执行时总报Unexpected token o in JSON at
                                    javascript的数据类型我们都知道, TypeScript支持与JavaScript几乎相同的数据类型,此外还提供了实用的枚举类型方便我们使用。
1、Typescript的原始数据类型
布尔类型(boolean)
	let isBool: boolean = false
	let isBool: boolean = true
	// 如果你写成其他类型的值,就会提示报错
	let isBool: boolean = 'string'
数值(number)
	let age:num
                                    // 读取多个文件示例
    public static async getAssetsFromLocal(accept:string = "*", bMul = false, func:any=null): Promise<string> {
        let document = Laya.Browser.document;
        let uploader = document.createElement('input');
        uploader.ty...