java下载服务器上的文件到客户端

我从数据库中查出数据后导出为DBF文件。。
但是导出后的文件是在服务器上。。
请问有什么方法可以使客户端在访问的时候下载此DBF文件呢。
听人说直接用http 给个链接。
具体怎么做有大侠知道么。。

java编程方法下载服务器上的文件到本地客服端,代码如下:

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
 
public class DownLoad {   
 public static void downloadFile(URL theURL, String filePath) throws IOException {  
   File dirFile = new File(filePath);
      if(!dirFile.exists()){ 
        //文件路径不存在时,自动创建目录
        dirFile.mkdir();
      }
  //从服务器上获取图片并保存
     URLConnection connection = theURL.openConnection();
     InputStream in = connection.getInputStream();  
     FileOutputStream os = new FileOutputStream(filePath+"\\123.png"); 
     byte[] buffer = new byte[4 * 1024];  
     int read;  
     while ((read = in.read(buffer)) > 0) {  
        os.write(buffer, 0, read);  
          }  
       os.close();  
       in.close();
  }   
     public static void main(String[] args) { 
      //下面添加服务器的IP地址和端口,以及要下载的文件路径
      String urlPath = "http://服务器IP地址:端口/image/123.png"; 
      
      //下面代码是下载到本地的位置
      String filePath = "d:\\excel"; 
  
      URL url = new URL(urlPath); 
  
          try { 
  
             downloadFile(url,filePath); 
  
           } catch (IOException e) { 
  
            e.printStackTrace(); 
  
         } 
  
      }   

}
温馨提示:内容为网友见解,仅供参考
第1个回答  2010-08-10
http://www.360doc.com/content/08/0327/19/3123_1148156.shtml里面对与资源的路径获取提供了解决方案,楼主可以自己去看下,我也是刚在做文件上传下载,发现上传容易,下载的路径提供还是有点疑惑,也刚好找了这个网址,希望对楼主能够有所帮助。本回答被提问者采纳
相似回答