List files from server in Applets JTable

Posted on 2006-05-31
Last Modified: 2008-01-09
Hi Everybody,

Help on how to do the following would be very much appreciated.  Thanks in advance!…

1.  I have a java *applet*, which contains a JTable.  I would like this JTable to display a list of files from the server that is hosting the java applet (Files from a single particular directory).    I just want to know if you can get a list of *server* files from an applet, I don't really need the code to create the JTable, display these, etc.

2.  When a user selects one of the files from the above-mentioned JTable, I would like a 'download' button.  Can anyone provide code that lets you download a file from an applet to the users PC?  (Preferably without having to ask the user where they want this saved each time).

Thanks again!
Question by:brent_watson
    LVL 92

    Assisted Solution

    two options would be:

    1.  generate the file list on the server and include it as applet parameters
    this would require the applet html page to be dynamically generated

    2. call a servlet (or some other server side component) on the server that returned the file list

    Author Comment

    Thanks for the response.  I created a php page to return my list of files, and will use that to populate the JTable.

    Any help on the other 1/2 of my issue? ie - Downloading a file from the server from an applet.

    LVL 30

    Accepted Solution

    >> Downloading a file from the server from an applet.

    It is possible. The applet can connect to the server from which it was downloaded and the servlet or PHP page that you have can send the file to it. You can make a request to get the file and read it in bytes:

    ByteArrayOutputStream bs = new ByteArrayOutputStream () ;
    int i ;

      i = () ;
      if ( i >= 0 )
        bs.write ( i ) ;
        break ;
    } while ( true ) ;

    Now you have all the bytes of the file in the byte-array output-stream.
    LVL 92

    Expert Comment

    LVL 14

    Expert Comment

    Communicating with a Web Server thru java

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
    An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
    Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now