I have external device connected to the computer. I'm using rxtx library to interface that device. that device transmits a byte immediately as replay to that bye that i send.

example
if i send '1' it replays a
'2' it replays b
....

first i Tried it for 1 byte. send '1' and receive a;
and it works fine.

In first case a[0] has expected value
 
       byte[] a;
        a = new byte[1024];
        char ch[] = {'1','2','3','4','5','6','7','8'};
        byte adc[] = new byte[8];
        int length;
        int i=0;
 
 try {
 
            out.write((byte)'1');
            length = in.read(a);
            if(length==1)
            {
                this.perameters.setTempreture(a[0]);//a[0] has expected value reading successful 
            }
 
 
        } catch (IOException ex) {
            System.out.println("Error in writing");
            Logger.getLogger(CommunicationLayer.class.getName()).log(Level.SEVERE, null, ex);
        }




but when i tried it for 8 bytes. it doesn't work.

In this case adc[0] has unexpected value.
       byte[] a;
        a = new byte[1024];
        char ch[] = {'1','2','3','4','5','6','7','8'};
        byte adc[] = new byte[8];
        int length;
        int i=0;
 
try {
           for(i=0;i<=7;++i)
           {
 
            out.write((byte)ch[i]);
            length = in.read(a);
            if(length==1)
            {
                adc[i] = a[0];
            }
           }
           this.perameters.setTempreture(adc[0]);//adc[0] is unexpected
        } catch (IOException ex) {
            System.out.println("Error in writing");
            Logger.getLogger(CommunicationLayer.class.getName()).log(Level.SEVERE, null, ex);
        }