In an experimental extension I am working on I use a function to get the source of a webpage and assign it to a variable. It worked perfectly fine. However I want to change the way it w开发者_StackOverflow中文版orks and get the content from a txt file.
I am hosting a txt file like: http//1.2.3.4/1.txt
.
What I want is to assign the contents of this txt file to a variable.
Function is here: http://jsfiddle.net/qumsm/.
(Function is not mine. I got it from another extension xpi which I cant remember right now. Respects to the coder of it.)
The function produces "ÿþP"
this result which I dont get.
That's a byte order mark, the file you are looking at seems to be using UTF-16 LE encoding. You need to use nsIConverterInputStream instead of nsIScriptableInputStream
when reading in that data and specify the correct encoding to convert from. nsIScriptableInputStream
is only useful when reading in ANSI data, not Unicode. See code example on MDN.
精彩评论