Welcome Guest.


How to use writeBoolean in DataOutStream

Asked by: Sarah Morris 198 views IT December 27, 2018

How to use writeBoolean in DataOutStream

3 Answers

  1. +4Votes  

    Use dateOutputStream and dataInputStream, which are processing streams that can be written and read directly to the base type.

    I will give you an example.

    1234567891011121314151617181920212223242526272829303132333435363738394041424344package com.suhayl.review.io; import java.io.ByteArrayInputStream;import java.io.ByteArrayOutputStream;import java.io.DataInputStream;import java.io.DataOutputStream;import  java.io.IOException; /** * ByteArrayOutPutStream : Write data to a byte array, * ByteArrayInputStream:  read out the data in the byte array.  * DataOutputStream : It is a processing stream. In this case, dateOutputStream sets a ByteArrayOutputStream that can write the primitive type directly.  * DataInputStream : It is a processing stream, in this case dataInputStream sets a ByteArrayInputStream, which directly reads the basic type. &Nbsp; *   * / public   class   Test_3_DataIO   {        public   static   void   main (String []   args)   {                ByteArrayInputStream   bis   =   null;                 ByteArrayOutputStream   bos   =   null;                 DataInputStream   dis   =   null;                 DataOutputStream   dos   =   null;                           () ByteArrayOutputStream;;         bos   =   new &nbsp                 dos   =   new   DataOutputStream (bos);                 try   {                        dos.writeInt (new   Integer (101));                       &nb sp; dos.writeDouble (new   Double (0.11111111));                    ; bis   =   new     &nbsp ByteArrayInputStream (bos.toByteArray ());                         dis   =   new   DataInputStream (bis);                         System.out.println (dis.readInt ());                         System.out.println (dis.readDouble ());                }   catch   (IOException   e)   {                        e.printStackTrace ();                }              finally {            try {                 dos.clos e();                dis.close();             } catch (IOException e) {                e.printStackTrace();            }         }    }}

    Kenneth Adams- December 28, 2018 |

  2. +8Votes  

    See the help file void write(byte[] b) b.length The byte is written to this output stream from the specified byte array. Void write(byte[] b, int off, int len) Writes len bytes from the specified byte array starting at offset off to this output stream. Abstract void write(int b) Writes the specified byte to this output stream. There is no write(String s) method.

    Robert Robinson- December 28, 2018 |

  3. +5Votes  

    This is a direct use of

    Amanda Hall- December 28, 2018 |