-3

我刚刚实现了一个 jsp 程序来将文件上传到我的 PC 文件夹中。此文件夹的路径是E:\UploadedFile. 我要下载的文件名是assad.xml(我刚刚上传的那个)。这就是我尝试下载它的方式。如果我错了,请检查我的代码并纠正我。

<%@page import="java.io.*,java.net.*"%>


 <%
  System.setProperty("http.proxyHost", "192.168.1.10");
    System.setProperty("http.proxyPort", "8080");
 try {
    /*
     * Get a connection to the URL and start up
     * a buffered reader.
     */
    long startTime = System.currentTimeMillis();  
    System.out.println("Connecting to URL...\n");  
    URL url = new URL("E://UploadedFiles/");
    url.openConnection();
    InputStream reader = url.openStream();  
    /*
     * Setup a buffered file writer to write
     * out what we read from the website.

     */
    FileOutputStream writer = new FileOutputStream("E:/assad.xml");
    byte[] buffer = new byte[153600]; // Buffer for 150K blocks at a time
    int totalBytesRead = 0;
    int bytesRead = 0;
    System.out.println("Reading ZIP file 150KB blocks at a time.\n");  

    while ((bytesRead = reader.read(buffer)) > 0){  
       writer.write(buffer, 0, bytesRead);
       buffer = new byte[153600];
       totalBytesRead += bytesRead;
    }  
    long endTime = System.currentTimeMillis();  

    System.out.println("Done. " + (new Integer(totalBytesRead).toString()) + " bytes
  read (" + 
           (new Long(endTime - startTime).toString())+ " millseconds).\n");
    writer.close();
    reader.close();
 }catch (MalformedURLException e){
    e.printStackTrace();
 }
 catch (IOException e){
    e.printStackTrace();
 }

 %>

我刚刚上传文件的文件夹的名称是UploadedFiles,它位于E: drive中。我要下载的文件的名称是assad.xml。它在此文件夹中可用。

4

1 回答 1

0

可能你倒置了文件名,就像 Renjith 说的那样。如需更一致的 API,请查看:http ://hc.apache.org/httpcomponents-core-ga/index.html

于 2013-01-15T13:25:22.123 回答