工作中遇到一些Sun JDK与IBM JDK不兼容的问题,记下来做个备忘
1. String.getBytes(String encoding)
try {
RandomAccessFile f = new RandomAccessFile("test.txt", "rw");
f.write("tets".getBytes(null));
f.close();
} catch (IOException e) {
e.printStackTrace();
}
}
IBM JDK 1.4 :
Exception in thread "main" java.lang.NullPointerException
at java.lang.StringCoding$EncoderCache.makeEncoder(StringCoding.java:198)
at java.lang.StringCoding$2.run(StringCoding.java:251)
at java.security.AccessController.doPrivileged1(Native Method)
at java.security.AccessController.doPrivileged(AccessController.java:351)
at java.lang.StringCoding$EncoderCache.getEncoder(StringCoding.java:248)
at java.lang.StringCoding.getEncoder(StringCoding.java:331)
at java.lang.StringCoding.encode(StringCoding.java:472)
at java.lang.String.getBytes(String.java:947)
at NullEncoding.main(NullEncoding.java:12)
2. 日文编码
try {
"".getBytes("Shift-JIS");
} catch (Exception e) {
e.printStackTrace();
}
}
SUN JDK 1.4 : OK
IBM JDK 1.4 :
java.io.UnsupportedEncodingException: Shift-JIS
at java.lang.StringCoding$EncoderCache.getEncoder(StringCoding.java:262)
at java.lang.StringCoding.getEncoder(StringCoding.java:331)
at java.lang.StringCoding.encode(StringCoding.java:472)
at java.lang.String.getBytes(String.java:947)
at ShiftEncoding.main(ShiftEncoding.java:17)
To Be Continue...