我有一个与该部分打开的文件类:保存文件用的JFileChooser保存对话框
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();
}
然后我想将这个文件保存在另一个文件中有:
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();
}
但它只会创建一个空文件!我该怎么做才能解决这个问题? (我想让我的课程打开所有类型的文件并保存它们)
一个建议:你也应该关闭'FileInputStream in'。 – 2010-03-04 17:25:12