dcsimg
URGENT PLEASE! How-to read a .jpg file as a bite array
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Yamini_Edupuganti
Posted On:   Monday, January 12, 2004 03:40 PM

How-to read a .jpg file as a bite array


I need to read a .jpg image as a byte array to pass as an argument to a method provided by my custom architecture. Please let me know how can I do that. Thank you, Yamini.

Re: URGENT PLEASE! How-to read a .jpg file as a bite array

Posted By:   Mark_Stewart  
Posted On:   Sunday, March 28, 2004 09:26 AM


import java.io.*;
/**
*
* @author Mark Stewart
*/
public class JPGGet {

public static void main(String[] args){
// Get file for length
File file=new File("c:/logo.jpg");
// Read fully
try{
DataInputStream dis=new DataInputStream(new FileInputStream(file));
byte[] bytes=new byte[(int)file.length()];
dis.readFully(bytes);
// Pass image bytye array to method
doSomethingWithImageBytes(bytes);
}catch(IOException ex){
// Do something if exception occurs
}
}

public static void doSomethingWithImageBytes(byte[] image){
System.out.println("Image has "+image.length+" bytes");
}

}

Re: URGENT PLEASE! How-to read a .jpg file as a bite array

Posted By:   Anonymous  
Posted On:   Tuesday, January 13, 2004 12:56 AM

You've got a good Apache API answering your needs : org.apache.commons.fileupload

Good luck !
About | Sitemap | Contact