I have a class that opens the files with this part:
JFileChooser chooser=new JFileChooser();
chooser.setCurrentDirectory(new File("."));
int r = chooser.showOpenDialog(ChatFrame.this);
if (r != JFileChooser.APPROVE_OPTION) return;
try {
Login.is.sendFile(chooser.getSelectedFile(), Login.username,label_1.getText());
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
then I want to save this file in another file with:
JFileChooser jfc = new JFileChooser();
int result = jfc.showSaveDialog(this);
if (result == JFileChooser.CANCEL_OPTION)
return;
File file = jfc.getSelectedFile();
InputStream in;
try {
in = new FileInputStream(f);
OutputStream st=new FileOutputStream(jfc.getSelectedFile());
st.write(in.read());
st.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
but it only creates an empty file! what should I do to solve this problem? (I want my class to open all kind of files and save them)