convert jpg file into byte file using java

I have a jpg image file, I want to convert it into byte file using java program, and what file extension i may use that. Because iReports requires, only byte file to show a static image in the report. such as a background image.
jayaprakashkgAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ProgrammingSmurfCommented:
not sure what you mean by Byte file?  You can read it into a byte array with something like this ...


package com.example.ExpertsExchange
 
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
 
public class ReadJPG {
 
	/**
	 * @param args
	 */
	public static void main(String[] args) {
	// TODO Auto-generated method stub
 
	try {
		FileInputStream fi = new FileInputStream("C:\\image.jpg");
		byte[] imageAsBytes = new byte[fi.available()];
		fi.read(imageAsBytes);
			
	} catch (FileNotFoundException ex) {
		// error processingpackage uk.allianz.test.kmg.dirlist;
 
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
 
public class ReadJPG {
 
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
 
		try {
			FileInputStream fi = new FileInputStream("C:\\image.jpg");
			byte[] imageAsBytes = new byte[fi.available()];
			fi.read(imageAsBytes);
			
		} catch (FileNotFoundException ex) {
			// error processing
		} catch (IOException ex) {
			// error pro
		}
	}
 
}	

Open in new window

0
ProgrammingSmurfCommented:
sorry ... i cut and paste twice by mistake ,,,, code snippet should be ,.,.,.
package uk.allianz.test.kmg.dirlist;
 
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
 
public class ReadJPG {
 
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
 
		try {
			FileInputStream fi = new FileInputStream("C:\\image.jpg");
			byte[] imageAsBytes = new byte[fi.available()];
			fi.read(imageAsBytes);
			
		} catch (FileNotFoundException ex) {
			
		} catch (IOException ex) {
			
		}
	}
 
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Software

From novice to tech pro — start learning today.