Node.js readFile txt add a question mark at the top of the content

I get some data from a .txt with a function fs.readFile(), but the top of the content is like "Alex libman"

All my 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 a question mark at the top of the content

Note: my titles0.txt is string data

+4
source share
1 answer

You need to convert the file to UTF-8 without specification . You can do this using this command in your terminal:

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

Or you can remove the specification with text editors such as Sublime Text ( File -> Save with Encoding -> UTF-8) or Notepad ++ ( Encoding -> Convert to UTF-8 without BOM).

+6

Source: https://habr.com/ru/post/1584645/


All Articles