注) byte列の文字列化で、UTF-16LE(リトルエンディアン)を使っているので、環境依存しそうです...
モノによっては、UTF-16BE(ビッグエンディアン)でうまく動くのかも。
- 手順 -
public static String getUncompressedUnicode(final byte[] string,
final int offset, final int len)
throws ArrayIndexOutOfBoundsException, IllegalArgumentException, UnsupportedEncodingException {
if ((offset < 0) || (offset >= string.length)) {
throw new ArrayIndexOutOfBoundsException("Illegal offset");
}
if ((len < 0) || (((string.length - offset) / 2) < len)) {
throw new IllegalArgumentException("Illegal length");
}
byte[] bstring = new byte[len * 2];
int index = offset;
// start with high bits.
for (int k = 0; k < (len * 2); k++) {
System.out.println("val: " + string[k]);
bstring[k] = string[index];
index++;
}
return new String(bstring, "UTF-16LE");
}
- 結果 -
-- Sheet1 -- 日本語文字 character 123.0 123.0 character 日本語文字 ddd ... -- 日本語シート名 -- 日本語文字 character 123.0 123.0 character 日本語文字
2002/08/07作成