Friday, January 03, 2014

byte to integers and back to byte in java

Path path = Paths.get("P:/pradyut/my pics/DSC_0411.jpg");
        try {
            byte[] data = Files.readAllBytes(path);
         
            byte[] data1=new byte[data.length];
            String str = "";
            int l =0;
            int k=0;
            System.out.println("The size of the file: " + data.length);
            /*Db obj = new Db();    
            obj.connect();
            obj.close();
            */
            for ( byte b : data) {
             
                //str = str + Integer.toBinaryString(b) + ",";
                k = b & 0xFF;
                System.out.print("," + k);
                data1[l] = (byte) k;
                l=l+1;
            }
         
            FileOutputStream fos = new FileOutputStream("P:/pradyut/my pics/pr.jpeg");
            fos.write(data1);
            fos.close();




No comments: