我认为java中的字符是16位,如java doc中所建议的那样.字符串不是这样吗?我有一个代码将对象存储到文件中:
public static void storeNormalObj(File outFile, Object obj) {
FileOutputStream fos = null;
ObjectOutputStream oos = null;
try {
fos = new FileOutputStream(outFile);
oos = new ObjectOutputStream(fos);
oos.writeObject(obj);
oos.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
oos.close();
try {
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
基本上,我试图将一个字符串存储"abcd"到文件中"output",当我output用编辑器打开并删除无字符串部分时,剩下的只是字符串"abcd",总共是4个字节.谁知道为什么?对于ASCII支持的字符串,java是否使用ASCII而不是UNICODE自动节省空间?谢谢