It s strange you get OtpErlangString on Java side when you use UTF8 characters. I get object of this type if I use ASCII characters only. If I add at least one UTF8 character, the resulting type is OtpErlangList (which is logical as strings are just lists of ints in Erlang) and then I can use its stringValue() method. So that after sending string form Erlang like:
(waco@host)8> {proc, java1@host} ! "ąćśźżęółńa".
[261,263,347,378,380,281,243,322,324,97]
On Java node 我收到并印刷了该文件:
OtpErlangList l = (OtpErlangList) mbox.receive();
System.out.println(l.stringValue());
产出正确:
ąćśźżęółńa
然而,如果你的情况不是这样,那么你会试图通过强迫OtpErlangList代表,例如,增加一个空洞的图象作为扼杀清单的第一个要素:
(waco@wborowiec)11> {proc, java1@wborowiec} ! [{}] ++ "ąćśźżęółńa".
[{},261,263,347,378,380,281,243,322,324,97]
Java一旁:
OtpErlangList l = (OtpErlangList) mbox.receive();
// get rid of an extra tuple
OtpErlangObject[] strArr = Arrays.copyOfRange(l.elements(), 1, l.elements().length);
OtpErlangList l2 = new OtpErlangList(strArr);
System.out.println(l2.stringValue());