Possible duplicate:Why Java OutputStream.write () accepts integers but writes bytes
Why OutputStream write() method of the OutputStream class take an integer instead of a byte when it actually writes data bytes by a byte?
OutputStream
write()
it is consistent with w / IntputStream.read() , and since most operations (sum, mul, div, etc.) are promoted to int, this eliminates the need for constant additions to byte .
IntputStream.read()
byte
I think everything is in order.
It actually writes one byte from this int (low 8 bits). See Documentation: http://docs.oracle.com/javase/1.4.2/docs/api/java/io/OutputStream.html#write%28int%29
Change I searched a bit and found this: Why Java OutputStream.write () accepts integers but writes bytes
You can use it to write either a signed or unsigned byte. Most byte streams accept unsigned bytes, and the corresponding InputStream.read () reads a non-negative int , which you can use for (byte) to make it signed.
int
(byte)
If you create a readObject and writeObject, you will be provided with ObjectInputStream and ObjectOutptuStream to read / write your custom serialization format for your object.
http://java.sun.com/developer/technicalArticles/ALT/serialization/
private void writeObject(ObjectOutputStream oos) throws IOException { oos.defaultWriteObject(); // Write/save additional fields oos.write(byteField); oos.writeObject(new java.util.Date()); } // assumes "static java.util.Date aDate;" declared private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException { ois.defaultReadObject(); // Read/initialize additional fields byteField = oos.read(); aDate = (java.util.Date)ois.readObject(); }
Source: https://habr.com/ru/post/903531/More articles:In any case, with the Entity Framework Code First of all, to get a good idea about the structure of the class? - entity-framework-4.1the size of the next datagram queue - UDP - c #Radiation IL to call the Math function - .netHow do I swap letters around input in python? - pythonTarget c division of two ints - objective-cThe stat_smooth limit for a specific range is rDomain limit when using socket.io? - socket.iosocket.io security - is this possible only from a specific domain? - node.jsWhy is the same code much slower in my BackGroundWorker stream than in my graphics stream? - performanceMustache / jQuery / javascript - how to execute a method on a variable mustache? - javascriptAll Articles