• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

writing UCS-2 encoded files with Java

 
William Stafford
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any way to write a UCS-2 file from a Java application?

We have a utility, written in Java, which reads and exports Oracle data as UTF-8 files which can then be imported by PostgreSQL. We would like to expand the utility to support import by Microsoft DB products which apparently do not recognize UTF-8 and instead require UCS-2.

When I try the usual way of writing out the files I get an UnsupportedEncodingException. This being the usual way:
BuffedFileWriter fileWriter =
new BufferedWriter(new OutputStreamWriter( new FileOutputStream(outFile), "UCS-2" ));

This UnsupportedEncoding sounds pretty final! Is there any way around this?

Thanks for any advice,
-=bill
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think as long as there aren't any codepoints beyond the BMP (i.e., above 65535), UCS-2 is identical to UTF-16, so you might try that. Depending on how you process the files, a byte order mark may be necessary.
 
William Stafford
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf,
Thanks for the reply. Is there anyway to know in advance what byte ordering would be used by MS SQL server? Or is this something that is typically specified on a per database basis?

Thanks again,
-=bill
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Byte order marks are only used in files, not databases. What you do need to worry about is the encoding the database uses -which by default is often ISO-8859 or even ANSI-, so you may have to change that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic