简体   繁体   English

阅读行的node.js文件不正确

[英]Incorrect reading lines node.js file

Hello I have a txt file to read with node.js (the contents of the txt file is below), when it reads the file with the javascript code below, the reading is performed correctly only on the first line of the file while the second it is not read correctly! 您好,我有一个要用node.js读取的txt文件(该txt文件的内容在下面),当它使用下面的javascript代码读取该文件时,仅在文件的第一行正确执行读取,而第二行则正确读取无法正确读取! How can I solve this? 我该如何解决?

File.TXT: FILE.TXT:

2;49.805;19.3386
3;49.805;19.3386

Node.js Code: Node.js代码:

fs.readFile(tempfilename, function (err, data) {
            if (err) {
                ManageError.SendError("error: " + err);
            } else {
                var array = data.toString().split("\n");
                for (i in array) {
                    var campi = array[i].split(';');
                    console.log(array[i]);
                    TIMESET(campi[0], campi[1], campi[2], "In");
                }
            }
        });

If you're working off a windows machine, windows .txt files have \\r\\n instead of just \\n. 如果要在Windows计算机上工作,则Windows .txt文件具有\\ r \\ n而不是\\ n。 This is evident if you add console.log(campi) and look at the second entry. 如果添加console.log(campi)并查看第二个条目,这是显而易见的。 Perhaps that's the issue? 也许这就是问题吗?

Otherwise on my system the code runs fine. 否则,在我的系统上,代码可以正常运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM