List files from server in Applets JTable

Posted on 2006-05-31
Medium Priority
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

objects earned 1000 total points
ID: 16804682
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

ID: 16804820
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

Mayank S earned 1000 total points
ID: 16804901
>> 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 = is.read () ;
  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

ID: 16804965
LVL 14

Expert Comment

ID: 16805117
Communicating with a Web Server thru java

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn different types of Android Layout and some basics of an Android App.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

850 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