javax.servlet.ServletOutputStream output = response.getOutputStream();
File urlfile =  new File(yourFile);
java.io.FileInputStream bis = new FileInputStream(yourFile); 
BufferedOutputStream bos = new BufferedOutputStream(output); 
byte[] buff = new byte[2048]; 
int bytesRead; 
while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) 

       bos.write(buff, 0, bytesRead); 

bos.close();
bis.close();

解决方案 »

  1.   

    不好意思,写错了,第二行的yourFile应该改成urlfile
      

  2.   

    非常感谢各位大侠,不过我还想问一个问题,就是如果在上面的代码中的youfile是一个链接地址如:http:\192.168.9.27\ecti\wavtemp\005021010150045.wav ,如果将这个链接地址变成一个有效的文件路径如:d:\\0050210150045呢?
      

  3.   

    你的有效地址是指什么,前面的d:\你自己制定的话,可以这样处理:先将url用\分隔成数组,去数组的最后一个元素,然后再起前面加上你的路径就行了。提供参考代码如下:
    public String[] stringSplit(String sourceString, String spliter)
      {
        String S1 = sourceString;
        String S2 = spliter;
        if(S1 == null || S2 == null || S1.equals("") || S2.equals(""))
        {
          return null;
        }
        else if(S1.length() <= S2.length())
        {
          if(S1.equals(S2))
          {
            return null;
          }
          else
          {
            String[] newArray = new String[1];
            newArray[0] = S1;
            return newArray;
          }
        }
        else
        {
          String temp_String1 = "";
          String temp_String2 = "";
          Vector array = new Vector();
          int length = S2.length();
          int max = 0;
          for(int i=0; i<S1.length(); i++)
          {
            max = (i + length >= S1.length()? S1.length():i + length);
            temp_String1 = S1.substring(i, max);
            if(temp_String1.equals(S2))
            {
              if(!temp_String2.equals(""))
              {
                array.addElement(temp_String2);
                temp_String2 = "";
              }
              i += length - 1;
            }
            else
            {
              if(max!=S1.length())
              {
                temp_String2 += temp_String1.substring(0,1);
              }
              else
              {
                temp_String2 += temp_String1;
                array.addElement(temp_String2);
                i += length;
                temp_String2="";
              }
             }
          }
          String[] returnArray = new String[array.size()];
          array.copyInto(returnArray);
          return returnArray;
        }
      }
      

  4.   

    你是要把服务器端的文件提供给客户端下载,我不明白你为什么要在服务器
    端用远程地址?如果一定要的话,那就写socket吧,打开一个httpFile很容易的。