This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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 Interview Guide this week in the Jobs Discussion 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

Create a byte array from a image file

ram ragu
Ranch Hand

Joined: Mar 12, 2002
Posts: 57
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
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...

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
I agree. Here's the link:
subject: Create a byte array from a image file
It's not a secret anymore!