cant write an image contained object to a file

HI, I am trying to save Vector object to a file which contains an image as one element.But i am not able to do that can anybody tell how to write the program.

i wrote the following program to do that task. but it's not working

can anybody tell what changes i have to make my program to work properly

my code as follows

import java.util.*;

import java.io.*;

import java.awt.*;

class ImageWrit implements Serializable

{

Image img;

public ImageWrit(){

img= Toolkit.getDefaultToolkit().getImage("a9.bmp");

}

}

class A{

public static void main(String s[])

{

FileOutputStream fout;

ObjectOutputStream out ;

Vector list = new Vector();

list.add(new ImageWrit());

try{

fout = new FileOutputStream("a.txt");

out = new ObjectOutputStream(fout);

out.writeObject(list);

System.out.println("object is saved");

}

catch(Exception e)

{

System.out.println("error");

}

}

}

[1054 byte] By [chokkanathana] at [2007-11-27 5:27:26]
# 1

It's easier to read your code (and help) when you use the code tags in you message...

it's also helpfull to know why you are not able to do it, compiler error, or runtime error, or...

third it's best to show a StackTrace in case of an Exception, like thatcatch(Exception e)

{

System.out.println("error"); // this tell nothing about the Exception

e.printStackTrace();

}

Maybe your problem is that the Image returned by ToolKit is not Serializable, you can search the internet for something like "java serializable image" for some hints... like making an ImageIcon of the image, which will be Serializable

public ImageWrit() {

img = new ImageIcon(Toolkit.getDefaultToolkit().getImage("a9.bmp"));

}

(also have a look at javax.imageio.ImageIO)

S_i_m_ua at 2007-7-12 14:48:57 > top of Java-index,Core,Core APIs...
# 2
PS: 4 times the same posting... not very wise to do that... most people don't like that, included mysefl, grrrrr
S_i_m_ua at 2007-7-12 14:48:57 > top of Java-index,Core,Core APIs...