Writing UTF8 text to file
Posted
by sonofdelphi
on Stack Overflow
See other posts from Stack Overflow
or by sonofdelphi
Published on 2010-05-15T13:20:36Z
Indexed on
2010/05/15
13:24 UTC
Read the original article
Hit count: 434
I am using the following function to save text to a file (on IE-8 w/ActiveX).
function saveFile(strFullPath, strContent)
{
var fso = new ActiveXObject( "Scripting.FileSystemObject" );
var flOutput = fso.CreateTextFile( strFullPath, true ); //true for overwrite
flOutput.Write( strContent );
flOutput.Close();
}
The code works fine if the text is fully Latin-9 but when the text contains even a single UTF-8 encoded character, the write fails.
The ActiveX FileSystemObject does not support UTF-8, it seems. I tried UTF-16 encoding the text first but the result was garbled. What is a workaround?
© Stack Overflow or respective owner