aspose file tools*
The moose likes Beginning Java and the fly likes Create a byte array from a image file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Create a byte array from a image file" Watch "Create a byte array from a image file" New topic
Author

Create a byte array from a image file

ram ragu
Ranch Hand

Joined: Mar 12, 2002
Posts: 57
Hello,
I am totally new to java and I just wanted to know how to create a byte array from an image file i.e i have a test.gif on my local drive
(c:/test.gif)
It might be simple .. but i just started learning java.. but need to do this rightaway ..
let me know.
Jason Ford
Ranch Hand

Joined: Aug 02, 2001
Posts: 54
If you want to create a byte array from a file, you just need to read in the file and store the result to an array:

If you really want a byte array instead of the char array, create a String with the char array and use the getBytes method on the String.
Unless I'm missing something...
HTH,
Jason


SCJP, SCWCD
hennie louw
Ranch Hand

Joined: Jul 03, 2001
Posts: 56



That might work but you can also try this

I'm just not sure if {array}.length value is the length of the array or the number of the last reffrence , but goo luck


Any Body can be paid to write good code, but brilliant code can only come from passion
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Create a byte array from a image file
 
Similar Threads
Want to create Image from byte [] from internet
how to create an image through bufferedimage,image and other helper class using byte array
ImageIcon Problem
create ImageIcon from bytes[], not from file
Create image from byte array