dcsimg
I have two image objects. I want to store these images into a file one after another. Can anyone suggest the code sample for this.???
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   chelikani_madhukumar
Posted On:   Tuesday, July 23, 2002 12:25 PM

I have two image objects. I want to store these images into a file one after another. Can anyone suggest the code sample for this.???

Re: I have two image objects. I want to store these images into a file one after another. Can anyone suggest the code sample for this.???

Posted By:   David_Drazic  
Posted On:   Tuesday, July 23, 2002 01:39 PM

import java.awt.*;

import java.util.*;

import java.io.*;



class ImageStorage {

public static void main(String args[])

throws Exception {


Toolkit kit = Toolkit.getDefaultToolkit();

Image image1 = kit.getImage("image1.jpg");


/*All images will be stored in a serializable
*Vector object, which will be written and
*retrieved from file as needed.*/


Vector images = new Vector();

images.addElement(image1);


File myFile = new File("file.dat");


/*To write the Vector object to file*/

ObjectOutputStream out =

new ObjectOutputStream(

new FileOutputStream(myFile));


out.writeObject(images);

out.flush();

out.close();


/*To write the second image to file, first

*retrieve the Vector,add the second image,

*and write it back to file.*/


ObjectInputStream in = new ObjectInputStream(

new FileInputStream(myFile));


images = (Vector)in.readObject();

in.close();


Image image2 = kit.getImage("image2.jpg");

images.addElement(image2);


ObjectOutputStream out2 =

new ObjectOutputStream(

new FileOutputStream(myFile));


out2.writeObject(images);

out2.flush();

out2.close();

}

}
About | Sitemap | Contact