PDA

View Full Version : Yet anther fun Java question




jtalerico
Feb 16, 2006, 03:39 PM
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...

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
Feb 16, 2006, 04:15 PM
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
Feb 16, 2006, 04:20 PM
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
Feb 16, 2006, 06:08 PM
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.

jtalerico
Feb 16, 2006, 06:10 PM
From what i have read, Commons and JFileChooser do not work together.

MarkCollette
Feb 16, 2006, 06:21 PM
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.