Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"

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

like image 837
Erdi Avatar asked Apr 25 '15 15:04

Erdi


1 Answers

You need to convert your file to UTF-8 without 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).

like image 102
Andrew Surzhynskyi Avatar answered Oct 03 '22 06:10

Andrew Surzhynskyi