try{ int max = (Integer) (ois.readObject()); byte[] serial = new byte[max]; for(int i = 0; i < max; i++) serial[i] = (Byte) ois.readObject(); ObjectInputStream oo = new ObjectInputStream(new ByteArrayInputStream(serial)); BufferedImage a = ImageIO.read(oo); oo.close(); File file = new File("Screenshot.jpg"); ImageIO.write(a, "jpg", file); }catch(ClassNotFoundException e){}