Reputation: 305
I am using JFileChooser in my Swing application. The user needs to browse to shared path such as \\ip\ (e.g. \\100.150.200.222\ -- in windows explorer this path is accessible and contains all shared folders on that machine). When the user types \\ip\ and clicks "OPEN" the file chooser window closes. Instead if the user gives any shared folder name in the remote system, then the file chooser displays the files (e.g. \\100.150.200.222\sharedFolder\). Kindly help on overcoming this so that the user can browse to \\ip\
Upvotes: 1
Views: 892
Reputation: 4277
\\100.150.200.222\
-- in windows explorer this path is accessible and contains all shared folders on that machine
Indeed, but \\100.150.200.222
is not a folder itself, which is why the file chooser does not work. In order to list the shared folders at this IP address, the solution is to use a 3rd party library as suggested in this post: Shares Under IP
String[] foldernames = new SmbFile("smb://100.150.200.222/").list();
Then I see three possible solutions to let the user choose a file:
Then, that's very simple: Get the name of the 1st shared folder with JCIFS, and open it in your file chooser.
File folder = new File("\\100.150.200.222\"+foldernames[0]);
new JFileChooser(folder).showSaveDialog(null);
JOptionPane.showInputDialog()
.String foldername = JOptionPane.showInputDialog(..., foldernames, ...);
File
and override a number of relevant methods. Then feed this file to your file chooser.Upvotes: 2