Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jtalerico

macrumors 6502
Original poster
Nov 23, 2005
358
0
So with JFileChooser I am trying to display the dir's and files on a remote server. Through FTP. But everytime it comes up, it will only show the client system filesystem.. Here is the code...

Code:
      JFrame frame = new JFrame("File Chooser");
                File curDir = new File(this.ftp.printWorkingDirectory());
                this.fc = new JFileChooser(curDir);
                int x = this.fc.showDialog(frame, "Open");
                if(x == this.fc.OPEN_DIALOG){
                    File dir = fc.getCurrentDirectory();
                    System.out.println(dir.toString());

It prints the local file system...

this.ftp is the FTPClient that is already connected to the server.
 

cubist

macrumors 68020
Jul 4, 2002
2,075
0
Muncie, Indiana
this.ftp.printWorkingDirectory() will give you a string like "/usr/local". File, and then JFileChooser gets passed that string and, of course, it will think you are talking about a local directory. I don't see why you would think that JFileChooser will work the way you want, but, if it does, it will need to have more information than that.

Please check results of all calls, and add comments.
 

jtalerico

macrumors 6502
Original poster
Nov 23, 2005
358
0
cubist said:
this.ftp.printWorkingDirectory() will give you a string like "/usr/local". File, and then JFileChooser gets passed that string and, of course, it will think you are talking about a local directory. I don't see why you would think that JFileChooser will work the way you want, but, if it does, it will need to have more information than that.

Please check results of all calls, and add comments.


Right
this.ftp.printWorkingDirectory will return a string. File takes a string. Then JFileChooser takes in a File, which the file points to the directory on the server.

You do not think that JFileChooser will work? Why not?
 

therevolution

macrumors 6502
May 12, 2003
468
0
jtalerico said:
Right
this.ftp.printWorkingDirectory will return a string. File takes a string. Then JFileChooser takes in a File, which the file points to the directory on the server.
You're passing a plain old String containing a pathname... how is it supposed to know that you want the path on the remote machine?

Have you tried doing a 'System.out.println("working dir: " + this.ftp.printWorkingDirectory());' to see what it looks like? That might help you understand what's going on.
 

MarkCollette

macrumors 68000
Mar 6, 2003
1,559
36
Toronto, Canada
JFileChooser shows File objects in a FileSystemView. The default FileSystemView is your local machine. If you want to make the JFileChooser show files on an FTP filesystem, then you have two choices:

1. Use native software that will map an FTP server into the local filesystem.
2. Write your own FileSystemView, which will expose the server's FTP filesystem, and pass this FileSystemView as a parameter to the JFileChooser.

I have personally written FileSystemViews to do the following:
- Show entries in a section of a hierarchial object oriented database, as if they were File objects. The also required extending File to support this.
- On older JVMs that didn't support showing the MS Windows Network Neighbourhood, I wrote JNI code to access the Win32 API for Network Neighbourhood, and wrapped it with a custom FileSystemView.
- An aggragate FileSystemView that could delegate the the "real" FileSystemView, or my database one, or my Network Neighbourhood one.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.