rendered paste body/* * MainApplet.java * * Created on July 31, 2006, 8:39 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */import java.applet.Applet;import java.awt.Graphics;import java.io.*;import java.net.*;/** * * @author Administrator */public class MainApplet extends Applet { static Graphics grap; /** Creates a new instance of MainApplet */ public MainApplet() { } public void paint(Graphics g) { grap = g; g.drawString("Hello, World",50,25); download("060729-Shore2Shore_Remake-v01-0.72b1-1.sdf", "test.sdf"); } public static void download(String address, String localFileName) { OutputStream out = null; URLConnection conn = null; InputStream in = null; try { URL url = new URL(address); out = new BufferedOutputStream( new FileOutputStream(localFileName)); conn = url.openConnection(); in = conn.getInputStream(); byte[] buffer = new byte[1024]; int numRead; long numWritten = 0; while ((numRead = in.read(buffer)) != -1) { out.write(buffer, 0, numRead); numWritten += numRead; } System.out.println(localFileName + "\t" + numWritten); } catch (Exception exception) { grap.drawString(exception.toString(), 50,50); } finally { try { if (in != null) { in.close(); } if (out != null) { out.close(); } } catch (IOException ioe) { } } } }