zoukankan      html  css  js  c++  java
  • Atitit 按照行读取文件 目录 1.1. 类库'readline' 1 1.2. 类库C:workspacedataindexGenerNodejssdkioFileUtils.js

    Atitit 按照行读取文件

     

    目录

    1.1. 类库'readline' 1

    1.2. 类库C:workspacedataindexGenerNodejssdkioFileUtils.js 1

    1.3. 使用 2

    2. ref 3

     

     

      1. 类库'readline'

    var readline = require('readline');

     

     

     

      1. 类库C:workspacedataindexGenerNodejssdkioFileUtils.js

     

    function readLines()

    {

        var fs = require('fs');

        

     

    }

     

    function readLinesFromtxt(fReadName,callback)

    {

        var fs = require('fs');

       

        var readline = require('readline');

        var fRead = fs.createReadStream(fReadName);

        var objReadline = readline.createInterface({

            input:fRead

        });

        var arr = new Array();

        objReadline.on('line',function (line) {

            arr.push(line);

            //console.log('line:'+ line);

        });

        objReadline.on('close',function () {

           // console.log(arr);

          callback(arr);

         //console.log("close evnt");

     

        });

     

    }

     

    exports.readLinesFromtxt =readLinesFromtxt

     

      1. 使用

     

     FileUtils = require("./sdk/io/FileUtils.js");

       FileUtils.readLinesFromtxt(newLocalfunction (list) {

          var newdir = 'c:\000tmp\' + path.filename + "Fld"

     

          try { fs.mkdirSync(newdir); } catch (e) { }

     

          console.log(list);

     

          for (line of list) {

             var pathM = require('path');

             var basename = pathM.basename(line)

             var lineFileName = newdir + "\" + basename + ".txt"

             try {

                fs.writeFileSync(lineFileNameline);

             } catch (error) {

     

             }

     

             //  console.log(key);

          }

       });

     

    })

     

     

    1. ref

     

    var readline = require('readline');

     

    /*

    * 按行读取文件内容

    * 返回:字符串数组

    * 参数:fReadName:文件名路径

    *      callback:回调函数

    * */

    function readFileToArr(fReadName,callback){

        var fRead = fs.createReadStream(fReadName);

        var objReadline = readline.createInterface({

            input:fRead

        });

        var arr = new Array();

        objReadline.on('line',function (line) {

            arr.push(line);

            //console.log('line:'+ line);

        });

        objReadline.on('close',function () {

           // console.log(arr);

            callback(arr);

        });

    }

    ————————————————

    版权声明:本文为CSDN博主「yajie_china」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。

    原文链接:https://blog.csdn.net/yajie_china/article/details/79407851

     

    (9+条消息)【Node.js】'readline' 逐行读取、写入文件内容 - Sodino的专栏 - CSDN博客.mhtml

  • 相关阅读:
    C# 加载 SQLite DLL问题
    Linux chroot 并使用之前系统设备节点
    I.MX6 initramfs.cpio.gz.uboot unpack
    I.MX6 eMMC 添加分区
    Git 一次性 pull push 所有的分支
    ARM compiler No such file or directory
    Linux sed 替换第一次出现的字符串
    C# WinForm 应用程序 开启Console窗口
    No 'Access-Control-Allow-Origin' header is present on the requested resource.
    C# 集合已修改;可能无法执行枚举操作
  • 原文地址:https://www.cnblogs.com/attilax/p/15197049.html
Copyright © 2011-2022 走看看