Need help in converting byte stream to Image
<p>Hi I have a requirement of read the byte stream from a file and convert that into Image. </p>

<p>can any one help me in resolving the issue?</p>

<p>I wrote code like this:</p>

<pre><code>public static void main(String[] args) {

        try {

            byte[] imageInByte;
            /*BufferedImage originalImage = ImageIO.read(new File(
                    "c:/darksouls.jpg"));*/

            RandomAccessFile f = new RandomAccessFile("C:\\path", "r");
            byte[] b = new byte[(int)f.length()];

            //System.out.println();
            //f.read(b);

            // convert BufferedImage to byte array
            /*ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ImageIO.write(originalImage, "jpg", baos);
            baos.flush();
            imageInByte = baos.toByteArray();
            baos.close();
 */
            // convert byte array back to BufferedImage
            InputStream in = new ByteArrayInputStream(b);
            BufferedImage bImageFromConvert = ImageIO.read(in);

            ImageIO.write(bImageFromConvert, "jpg", new File(
                    "c:/new-darksouls.jpg"));

        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
</code></pre>

<p>I am getting the bellow exception:</p>

<p>Exception in thread "main" java.lang.IllegalArgumentException: im == null!</p>
