Question: I need to convert 2 byte array ( byte[2] ) to integer value in java. How can I do that?

Answer: 
You can use [`ByteBuffer`](http://download.oracle.com/javase/6/docs/api/java/nio/ByteBuffer.html) for this:

```
ByteBuffer buffer = ByteBuffer.wrap(myArray);
buffer.order(ByteOrder.LITTLE_ENDIAN);  // if you want little-endian
int result = buffer.getShort();

```

See also [Convert 4 bytes to int](https://stackoverflow.com/q/2383265/139010).
```
import java.io.*;
public class ByteArray {

    public static void main(String[] args) throws IOException {
        File f=new File("c:/users/sample.txt");
        byte[]b={1,2,3,4,5};
        ByteArrayInputStream is=new ByteArrayInputStream(b);
        int i;
        while((i=is.read())!=-1) {
            System.out.println((int)i); 
            FileOutputStream f1=new FileOutputStream(f);
            FileOutputStream f2=new FileOutputStream(f);
            ByteArrayOutputStream b1=new ByteArrayOutputStream();
            b1.write(6545);
            b1.writeTo(f1);
            b1.writeTo(f2);
            b1.close();
        }

```