Hello. I've built a java application in which the user loads a number of images into the application at run time. The application stores the path to the image. When the application needs the image it constructs a new imageicon with the path specified, when it no longer needs it it deletes it for garbage collector. When the user saves they specify a folder to save in as well as a name to save as, with JFileChooser. My main data object is serialized here with the specified name, + each image in the program is loaded and written to this location as well, with the specified name + an identifier number. When this file is loaded by the program later it will go to these images it has written when it needs them instead of the original images on disk, which may be in various places on the computer.
So when I save my program with name "Balloon" in folder "Rex" Rex will hold Balloon, as well as BalloonImage0, BalloonImage0-1, BalloonImage0-2, etc. But I would rather just have *one* file saved on disk, instead of saving multiple files to a folder. I want people to be able to move the saved document of the program as a single file, and also not to be able to delete an image in the file as they would be able to do now. So I guess I would want the folder "Rex" to look like one file.
Could anybody help me out with how to do this? I am new to java and I'm not even sure if I'm asking this the right way. Thank-you for anybody's reply.
Normally if you want to distribute your Java program together with some resources (like images), you just package them all into an executable jar file.
But I'm a bit confused by the way you describe the user saving these files in a directory. The user isn't going to be distributing the application, you are. So why should the user be forced to put these images in some sort of hidden place? Especially since the user is the one choosing the directory to save them in; the user is going to be rather confused to find that the images aren't actually in that directory. I guess I don't really understand the reason for your requirements and find them rather peculiar.
posted 10 years ago
Thanks for the speedy reply.
In this case the user is creating something. The same way the user of a text writing program enters text and saves it to a file. The user is inputting into the program, among other things, images via JFileChooser. When they choose these files and the program runs whenever it needs the photos it will go to the images specified by the user during runtime. But, when the user saves to a location, the program copies all those images from various locations into the new location where the file will be saved (a folder), with the rest of saved data of the program, a serialized object of the application.
This way if a user were to load the saved files after the original images had been moved, the program would still work because it would go to the (new) images it had saved into the save folder that was specified when saving, which are just copies of the original images the user specified during run time.
So my goal is instead of the program saving multiple things into the path the user specified to save in, all of which are loaded when the user loads the serialized object, to just save one "thing", one file. It would be the document for my application.