hello,
Iv been trying to write a java program to read an image from a list of images in a file I.E:
- File
- Filename
- Image1
- Filename
- Image2
- Filename
- Image3
The problem i am having is that the filename's are string objects followed by an image. So i was wondering if anyone could point me in the right direction to read the file i have written.
public class imageloader {
String name;
BufferedImage image;
public imageloader(String url)
{
try {
FileInputStream saveFile = new FileInputStream(url);
try {
ObjectInputStream restore = new ObjectInputStream(saveFile);
this.name = (String) restore.readObject();
this.image = ImageIO.read(restore);
System.out.println(this.name);
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
This is how i am how i am saving the file
try{
FileOutputStream saveFile=new FileOutputStream("testfile");
ObjectOutputStream save = new ObjectOutputStream(saveFile);
// Now we do the save.
save.writeObject(this.name);
ImageIO.write(image, "png", saveFile);
// Close the file.
save.close(); // This also closes saveFile.
}
Currently it throws no errors, but does not seem to actually read the data back into the buffered image. Any Ideas?