写出抛出错误先 
MalformedURLException

解决方案 »

  1.   

    把那个网址改成http://www.tom.com/index.html。
    这样java就知道用的协议是http public static void main(String args[]) {
    char[] bytes;
    try {
    File file = new File("g:/a.html");
    URL url = new URL("http://www.tom.com/index.html");
    int byteSize = 1024;
    System.out.println("dfsdf");
    int num;
    bytes = new char[byteSize];
    BufferedReader in =
    new BufferedReader(new InputStreamReader(url.openStream()));
    BufferedWriter out =
    new BufferedWriter(
    new OutputStreamWriter(new FileOutputStream(file)));
    while ((num = in.read(bytes, 0, byteSize)) != -1)
    out.write(bytes, 0, num);
    System.out.println("写了" + num + "个");
    }
    catch (Exception e) {
    e.printStackTrace();
    } }
      

  2.   

    请问file有这样构造方法吗??File file=new File(URL url);
    上次方法只能下载文本文件,下载exe文件就会出错
    该怎么样下载exe文件呢
      

  3.   

    好像是因为用了Reader, Writer的缘故吧,因为它们是面向字符的
    二进制文件要用面向字节流的InputStream, OutStream