下载必须要定义好文件名,如何改为下载的时候,弹出“打开”、“保存”、“取消”的对话框,怎么改呢?请教高手指教。
这是我写的:
ftpClient = new FtpClient();
ftpClient.openServer(server);
ftpClient.login(user, password);
ftpClient.binary();
TelnetInputStream is=ftpClient.get(filename);
File file_out=new File("d:/1.doc");//输出文件名,要改为自定义,怎么改呢?
FileOutputStream os=new FileOutputStream(file_out);
byte[] bytes=new byte[1024];
int c;
while ((c=is.read(bytes))!=-1) {
os.write(bytes,0,c);
}
is.close();
os.close();
ftpClient.closeServer();
------解决方案--------------------
import javax.swing.*;
ftpClient = new FtpClient();
ftpClient.openServer(server);
ftpClient.login(user, password);
ftpClient.binary();
TelnetInputStream is=ftpClient.get(filename);
JFileChooser jfc = new JFileChooser("d:\\");
int r = jfc.showSaveDialog(null);
File file = null;
if (r == JFileChooser.APPROVE_OPTION) {
file = jfc.getSelectedFile();
} else {
return;
}
//File file_out=new File("d:/1.doc");//输出文件名,要改为自定义,怎么改呢?
FileOutputStream os=new FileOutputStream(file_out);
byte[] bytes=new byte[1024];
int c;
while ((c=is.read(bytes))!=-1) {
os.write(bytes,0,c);
}
is.close();
os.close();
ftpClient.closeServer();