Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How write text to a file and encode it as UTF-8?

My code write Text to file in Adobe Script (.jsx):

var xml = " 小塚ゴシック Pro"

var file = new File(output);
file.open("w"); 
file.write(xml);
file.close();

But result encode UTF-8 can't display: ϬӋēĖĢĎ Pro It only can display text " 小塚ゴシック Pro" , if set encode of file is Shift-JIS.

How write text to File by Encode UTF-8?

like image 925
D T Avatar asked Nov 24 '25 16:11

D T


2 Answers

Try this:

file.encoding = "UTF-8";

And here is a sample, for reference.

like image 125
loxxy Avatar answered Nov 27 '25 05:11

loxxy


I had the same issue with polish chars and had to use UTF-16 vs UTF-8.

var xml= "小塚ゴシック Pro"   
var file = new File(output);
file.encoding = "UTF-16";
file.open("w");   
file.write(xml);
file.close();
like image 40
ccpotter Avatar answered Nov 27 '25 06:11

ccpotter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!