共享目录文件 下载
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="java.io.*" %>
<%
  
   OutputStream output = null;
   FileInputStream fis = null;
    File file = null;
   Process process = null;   
   byte[] b = new byte[1024];
    int i = 0;
    String fileName = "aa.txt";
    //共享目录文件的路径
    String filePath = "\\\\iesc-office3\\IESC_Web_Portal_Data\\PDM";
  
   Runtime rt = Runtime.getRuntime();
  
    //使用net use 连接共享目录
   String cmd = "net use \\\\iesc-office3\\IESC_Web_Portal_Data Aa77777 /USER:IESC\\IESCPDMUser";
   //断开连接
   String cmdDel = "net use \\\\iesc-office3\\IESC_Web_Portal_Data /del";
   
   try {
    process = rt.exec(cmd);  
   response.setContentType("application/x-octetstream;charset=UTF-8"); 
   response.addHeader("Content-Disposition","attachment; filename=\"" + java.net.URLEncoder.encode(fileName, "UTF-8").replace("+", " ") + "\"");
    
  output  = response.getOutputStream();  
  fis = new FileInputStream(filePath + "\\" + fileName);
     while((i = fis.read(b)) > 0){
      output.write(b, 0, i);
     }
  
       output.flush();
       out.clear();
  out = pageContext.pushBody();
  rt.exec(cmdDel);    
   } catch (Exception e) {
    e.printStackTrace();  
   } finally {
        if (output != null) {
            output.close();
            output = null;
        }
        
        if (fis != null) {
            fis.close();
            fis = null;
        }
       Runtime.getRuntime().exec(cmdDel); 
    }
%>
.jpg) 
  
 
                     
                    
                 
                    
                
 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号