Yet anther fun Java question

Discussion in 'Mac Programming' started by jtalerico, Feb 16, 2006.

  1. macrumors 6502

    Nov 23, 2005
    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();
    It prints the local file system...

    this.ftp is the FTPClient that is already connected to the server.
  2. macrumors 68020

    Jul 4, 2002
    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.
  3. thread starter macrumors 6502

    Nov 23, 2005

    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?
  4. macrumors 6502

    May 12, 2003
    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.
  5. thread starter macrumors 6502

    Nov 23, 2005
    From what i have read, Commons and JFileChooser do not work together.
  6. macrumors 68000


    Mar 6, 2003
    Calgary, 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.

Share This Page