简体   繁体   中英

Saving file as a double byte unicode in Java?

Okay, I'm running Java6 (App requirement) and I need to save a file in unicode format (no big endian or low endian), only double byte unicode. I did this:

 BufferedWriter bw = new BufferedWriter(
     new OutputStreamWriter(new FileOutputStream(f), "UTF-8"));
 bw.write(dec+",");
 bw.flush();
 bw.close();

where dec is a string.

I also tried UTF-16 and Unicode. They all write a unicode big endian file. The problem is, this file is read by a scripting language that only accept double byte unicode and ANSI too but I want to use unicode. http://www.mql5.com/en/docs/constants/io_constants/fileflags

Any idea how to do this?

Inferring from your question that it's the endianness which is the problem, you want UTF-16LE as the encoding name. From the Charset docs listing the mandatory encodings which are always supported:

UTF-16LE - Sixteen-bit UCS Transformation Format, little-endian byte order

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM