I read that Java uses internal UTF-16 encoding. that is, I understand that if I have: String var = "जनमत"; then “जनमत” will be internally encoded in UTF-16. So, if I upload this variable to some file, for example, below:
fileOut = new FileOutputStream("output.xyz"); out = new ObjectOutputStream(fileOut); out.writeObject(var);
will there be an encoding of the string "जनमत" in the file "output.xyz" in UTF-16? Also, later, if I want to read from the file "output.xyz" via ObjectInputStream, can I get a view of the UTF-16 variable?
Thank.
, ... "जनमत" "output.xyz" UTF-16?
, ObjectOutputStream . , ObjectInputStream. ( - IIRC , - , , XML JSON - .)
ObjectOutputStream
ObjectInputStream
, "output.xyz" ObjectInputStream, UTF-16 ?
ObjectInputStream, . java.lang.String, ( ), UTF-16, , getBytes() ( , ).
java.lang.String
. , , ; , JVM, .
: UTF-16, - UCS-2; 2 ( 2 , .. 4 ).
ObjectOutputStream -, UTF-8, UTF-8, 2- , UTF-8 (- ), 0.
, , " , String, String", . JDK .
writeUTF() , , . "writeObject()" , .
, ObjectOutputStream.writeString() UTF "" UTF "" UTF, "long", javadoc
ObjectOutputStream.writeString()
The long UTF format is identical to the standard UTF, except that it uses an 8 byte header (instead of the standard 2 bytes) to transmit the UTF encoding length.
I got this from code ...
private void writeString(String str, boolean unshared) throws IOException { handles.assign(unshared ? null : str); long utflen = bout.getUTFLength(str); if (utflen <= 0xFFFF) { bout.writeByte(TC_STRING); bout.writeUTF(str, utflen); } else { bout.writeByte(TC_LONGSTRING); bout.writeLongUTF(str, utflen); } }
and writeObject(Object obj)they do check
writeObject(Object obj)
if (obj instanceof String) { writeString((String) obj, unshared); }
Source: https://habr.com/ru/post/1779229/More articles:Добавить контекст веб-приложения в Jetty - javaHow can LiveDocx in PHP be used to read .doc & .docx files and read the text inside it and save it in HTML? - phpjava.util.logging Использование ConsoleHandler и не просмотр вывода system.err в окне IntelliJ IDEA 9 или Mac Terminal - intellij-ideaКак фильтровать данные Json в браузере? - jsonsql anywhere 5.5 database connects to sql anywhere 12 - sqlCustomers defined by Biztalk customer have signed - soaWhen is the right time to call robot.cleanUp () - javaHow to separate a possible URI from other content in PHP? - javascriptiPhone & UISegmentedControl - Change images and save title? - iphoneHow to take a function as an argument? (Python) - pythonAll Articles