Java Applet - how to download a file???

V

Vatan

hello,

i programmed an applet that is creating a file.
actually this file is created on server. everybody who wnats this file
have to go to the server and must copy it to his own computer. not
nice!!!

do you know how i can this file download directly to the client
computer???

rgrds
Vatan
 
A

Andrew Thompson

i programmed an applet that is creating a file. ...
do you know how i can this file download directly to the client
computer???

Yep. I posted a solution to a thread
titled 'applet showDocument work with file protocol'
on the 14th, but strangely it is not showing
at Google, so here it is again..

<sscce>
import java.applet.Applet;
import java.awt.*;
import java.net.*;

/** Can a Java Applet use 'showDocument' for
files? This small example demonstrates you can.
@author Andrew Thompson
@version 2004-04-15 */
public class FileFromServerApplet extends Applet {
public void init() {

TextArea ta = new TextArea();
add( ta );
validate();

URL url;
try {
url = new URL( getCodeBase().
toExternalForm() + "FileFromServerApplet.java");
getAppletContext().showDocument( url, "_blank" );
ta.setText( "File displayed" );
} catch (Exception e) {
ta.setText( e.toString() );
}
}
}
</sscce>

Of course, if you user complains,
'but that shows in the browser window'
tell them 'it's your own damn browser -
configure it how you want it' ..then
stride off, whistling loudly. ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,076
Latest member
OrderKetoBeez

Latest Threads

Top