To download FTP to a local system, you need to open a file storage dialog box. The local operating system must support windows, Linux, and Mac. Therefore, Java javax. Swing. jfilechooser should be used;
So I wrote a testProgramAs follows:
Code
Public Static Void Main (string [] ARGs ){
String retstr = "" ;
Jfilechooser C = New Jfilechooser ();
C. setfileselectionmode (jfilechooser. directories_only );
C. setdialogtitle ( " Select the target folder to download " );
C. setdialogtype (jfilechooser. save_dialog );
Int RET = C. showsavedialog ( Null );
If (Ret = Jfilechooser. cancel_option ){
Retstr = "" ;
}
Else If (Ret = Jfilechooser. approve_option ){
Retstr = C. getselectedfile (). getabsolutepath ();
System. Out. println (retstr );
// System. Out. println (system. getproperty ("OS. Name "));
}
Else If (Ret = Jfilechooser. error_option ){
Retstr = "" ;
}
}
Running in Windows is normal. The saved folder address can be obtained normally, but it is found strange in Mac. For example, if/volume/ftptest/is selected and double-click to open it, the obtained path will be/volume/ftptest/, that is, the target folder will be repeated. However, if the folder is directly selected but not entered, the correct path will be returned...
It is preliminarily determined that showsavedialog of jfilechooser does not support cross-platform platforms, or that the MAC system does not support Java well. Later I searched for a solution and found the solution on a foreigner's blog:
The problem occurs when you use chooser. showdialog or chooser. showsavedialog instead of chooser. showopendialog. on XP chooser. showdialog returns the correct path under the example given by the op, but on Mac OS 10.5.7 (and probably earlier versions as well) You'll get ~ /Desktop.
Do not use showdialog and showsavedialog on Mac ....
So, the aboveCodeChange showsavedialog to showopendialog to solve the problem.