Witam!
Mam problem który polega na tym że nie mogę dojść do tego jaki błąd jest w poniższym aplecie.Chodzi mi oto żeby ściągnął plik exe na lokalną partycję c:.
Po poprawnym skompilowaniu i zainicjowaniu appletu plik sie nie pobiera.
import java.io.*;
import java.net.*;
import java.net.URL;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class myurl extends Applet implements ActionListener
{
Button button = new Button("Transfer");
public void init()
{
button.addActionListener(this);
button.setActionCommand("ok");
add(button);
} // init
public void Transfer()
{
int zaehler = 0;
try
{
URL url = new URL("http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe");
OutputStream out = new FileOutputStream("C:\\new.exe");
InputStream in = url.openStream();
int len;
byte b[] = new byte[100];
while ((len = in.read(b)) != -1)
{
out.write(b, 0, len);
System.out.println(zaehler);
zaehler++;
} // while
out.close();
in.close();
button.setLabel("Fertig");
} // try
catch (MalformedURLException e)
{
System.err.println(e.toString());
// System.exit(1);
} // catch Malformed
catch (IOException e)
{
System.err.println(e.toString());
// System.exit(1);
} // catch IOEx
} // Transfer
//******************************************************* actionPerformed
public void actionPerformed(ActionEvent ereignis)
{
// Variablen
String kommando = ereignis.getActionCommand();
if (kommando.equals("ok"))
{
try
{
button.disable();
Transfer();
}
catch(Exception e) // performed
{} // keine Fehler zu erwarten
} // if
} // void actionPerformed()
} // class MyURL