简体   繁体   English

node.js readFile txt在内容顶部添加问号

[英]node.js readFile txt add question mark at top of content

i am getting some datas from .txt with fs.readFile() function but top of the content is like "?Alex libman" 我从.txt获得了一些带有fs.readFile()函数的数据,但内容的顶部是“?Alex libman”

My whole code ; 我的整个代码;

fs.readFile(__dirname+"/txts/generate/titles0.txt", "utf-8", function (ex, titles) {
var titlesArr =  titles.split("\r\n");
console.log(titlesArr);
});

Result; 结果;

["?Alex libman","Kroya Barzo","Deliah Krbo"]

Always , there is question mark at top of content 总是,内容顶部有问号

Note:my titles0.txt is line by line data 注意:我的titles0.txt是逐行数据

You need to convert your file to UTF-8 without BOM . 您需要将文件转换为UTF-8而不使用BOM You can do that by using this command in your terminal: 您可以在终端中使用此命令来执行此操作:

tail --bytes=+4 utf8_with_bom.txt > utf8_without_bom.txt

Or you may remove BOM with the help of text editors like Sublime Text ( File -> Save with Encoding -> UTF-8 ) or Notepad++ ( Encoding -> Convert to UTF-8 without BOM ). 或者您可以借助文本编辑器(如Sublime Text( File -> Save with Encoding -> UTF-8 )或Notepad ++( Encoding -> Convert to UTF-8 without BOM File -> Save with Encoding -> UTF-8 )来删除BOM。

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

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