下面这个程序是TRY
import java.io.*;
import java.net.*;public class GetURL {
  public static void main(String[] args){
    InputStream in = null;
    OutputStream out = null;
    int i = 0;
    i++;
    try{
      if((args.length != 1) && (args.length != 2)){
        throw new IllegalArgumentException("Wrong number");
      }
      URL url = new URL(args[0]);
      in = url.openStream();
      if(args.length == 2)
        out = new FileOutputStream(args[1]);
      else
        out = System.out;
      byte[] buffer = new byte[4096];
      int bytes_read;
      while((bytes_read = in.read(buffer)) != -1)
        out.write(buffer,0,bytes_read);
    }catch(Exception e){
      System.err.println(e);
    }
    finally{
      try{in.close();out.close();}catch(Exception e){}
    }
  }
}

解决方案 »

  1.   

    命令行如:
    javac GetURL http://www.google.com/或者javac GetURL http://www.google.com/ c:/temp.txt
      

  2.   

    // 写出流信息
      int i;
      while ((i=fileInputStream.read()) != -1) {
       out.write(i);
      }
      fileInputStream.close();
      out.close();
      

  3.   

    谢谢上面二位的回答!!
    我已经在Bean下生成了这个文件
    我现在的意思是这样:不在服务器端直接生成一个临时文件,因为这样生成的临时文件在下载完成之后还要在服务端执行一次删除操作。如果所生成的文件存在内存中,从内存中下载,就不用临时文件了,也不用删除文件了,其不是很美么。
      

  4.   

    response.setContentType(typ);
    把typ改×你的文件格式的mime头。
    设置一下。