Use this:
Bitmap bmp = null; ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 100, stream); byte[] byteArray = stream.toByteArray();
for this you can use this:
FileInputStream fileInputStream = null; File file = new File("yourfile"); byteArray = new byte[(int) file.length()]; try { //convert file into array of bytes fileInputStream = new FileInputStream(file); fileInputStream.read(bFile); fileInputStream.close(); //convert array of bytes into file FileOutputStream fileOuputStream = new FileOutputStream("C:\\testing2.txt"); fileOuputStream.write(bFile); fileOuputStream.close(); System.out.println("Done"); } catch (Exception e) { e.printStackTrace(); }
and for more information go here
Piyush
source share