简单的下载代码
import java.io.File;import java.io.FileOutputStream;import java.io.InputStream;import java.net.HttpURLConnection;import java.net.URL;public class RbdTest {private static String musicURL = "http://droidreader.googlecode.com/files/droidreader-0.4.apk";private static String filename = "sb.apk";public static void main(String[] args) {download();}private static void download() {try {// 读取链接地址歌曲文件流URL url = new URL(musicURL);HttpURLConnection conn = (HttpURLConnection) url.openConnection();conn.setDoInput(true);conn.connect();InputStream is = conn.getInputStream();// 创建本地保存流的文件File musicFile = new File("c:/", filename);FileOutputStream fos = new FileOutputStream(musicFile);byte[] bt = new byte[1024];int i = 0;while ((i = is.read(bt)) > 0) {fos.write(bt, 0, i);}fos.close();is.close();} catch (Exception e) {e.printStackTrace();}}}
?