<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    weizi2012

    weizi2012

    java 文件下載

    /**
      * 本地下載
      *
      * @param response
      * @throws FileNotFoundException
      */
     public void downloadLocal(HttpServletResponse response)
       throws FileNotFoundException {
      // 下載本地文件
      String fileName = "Operator.doc".toString(); // 文件的默認(rèn)保存名
      // 讀到流中
      InputStream inStream = new FileInputStream("c:/Operator.doc");// 文件的存放路徑
      // 設(shè)置輸出的格式
      response.reset();
      response.setContentType("bin");
      response.addHeader("Content-Disposition", "attachment; filename=\""
        + fileName + "\"");
      // 循環(huán)取出流中的數(shù)據(jù)
      byte[] b = new byte[100];
      int len;
      try {
       while ((len = inStream.read(b)) > 0)
        response.getOutputStream().write(b, 0, len);
       inStream.close();
      } catch (IOException e) {
       e.printStackTrace();
      }
     }

     /**
      * 網(wǎng)絡(luò)文件下載
      *
      * @param response
      * @throws MalformedURLException
      */
     public void downloadNet(HttpServletResponse response)
       throws MalformedURLException {
      // 下載網(wǎng)絡(luò)文件
      int bytesum = 0;
      int byteread = 0;
      URL url = new URL("windine.blogdriver.com/logo.gif");
      try {
       URLConnection conn = url.openConnection();
       InputStream inStream = conn.getInputStream();
       FileOutputStream fs = new FileOutputStream("c:/abc.gif");
       byte[] buffer = new byte[1204];
       @SuppressWarnings("unused")
       int length;
       while ((byteread = inStream.read(buffer)) != -1) {
        bytesum += byteread;
        System.out.println(bytesum);
        fs.write(buffer, 0, byteread);
       }
      } catch (FileNotFoundException e) {
       e.printStackTrace();
      } catch (IOException e) {
       e.printStackTrace();
      }
     }

     /**
      * 支持在線打開下載
      *
      * @param filePath
      * @param response
      * @param isOnLine
      * @throws Exception
      */
     public void downLoad(String filePath, HttpServletResponse response,
       boolean isOnLine,String fname) throws Exception {
      System.out.println("filePath:" + filePath);
      File f = new File(filePath);
      if (!f.exists()) {
       response.sendError(404, "File not found!");
       return;
      }
      BufferedInputStream br = new BufferedInputStream(new FileInputStream(f));
      byte[] buf = new byte[1024];
      int len = 0;
      response.reset(); // 非常重要
      if (isOnLine) { // 在線打開方式
       URL u = new URL("file:///" + filePath);
       response.setContentType(u.openConnection().getContentType());
       response.setHeader("Content-Disposition", "inline; filename="
         + fname);
       // 文件名應(yīng)該編碼成UTF-8
      } else { // 純下載方式
       response.setContentType("application/x-msdownload");
       response.setHeader("Content-Disposition", "attachment; filename="
         + fname);
      }
      OutputStream out = response.getOutputStream();
      while ((len = br.read(buf)) > 0)
       out.write(buf, 0, len);
      br.close();
      out.close();
     }

    posted on 2012-09-27 10:57 jiangwei 閱讀(1304) 評(píng)論(2)  編輯  收藏

    Feedback

    # re: java 文件下載 2012-09-27 15:11 遠(yuǎn)程考勤

    下載圖的就是速度和便捷  回復(fù)  更多評(píng)論   

    # re: java 文件下載 2012-09-28 13:04 天津公積金取

    這個(gè)是什么玩意兒其實(shí)也不懂  回復(fù)  更多評(píng)論   



    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     

    My Links

    Blog Stats

    常用鏈接

    留言簿

    隨筆檔案

    文章檔案

    搜索

    最新評(píng)論

    主站蜘蛛池模板: 奇米影视亚洲春色| 免费a级毛片网站| 亚洲导航深夜福利| 四虎国产精品永久免费网址 | 青草草在线视频永久免费| 亚洲欧洲日本国产| 免费观看AV片在线播放| 亚洲综合校园春色| 可以免费看的卡一卡二| 456亚洲人成在线播放网站| 女人被男人桶得好爽免费视频| 中文字幕亚洲综合久久综合| 大学生a级毛片免费观看| 亚洲av无码一区二区三区天堂| 国产在线a不卡免费视频| 免费手机在线看片| 亚洲精品乱码久久久久久按摩 | 黄 色一级 成 人网站免费| 久久久久亚洲精品中文字幕| 精品国产麻豆免费人成网站| 亚洲国产综合自在线另类| 成人免费看黄20分钟| 国产精品久久亚洲一区二区| 亚洲中文字幕无码久久2017 | 在线免费播放一级毛片 | 亚洲国产一成人久久精品| 亚洲国产精品免费视频| 亚洲最大中文字幕无码网站| 亚洲国产一成久久精品国产成人综合| 久久www免费人成精品香蕉| 亚洲免费在线播放| 成人免费无码大片a毛片| 国产精品综合专区中文字幕免费播放| 亚洲Av无码精品色午夜| 女人被男人躁的女爽免费视频| EEUSS影院WWW在线观看免费| 亚洲w码欧洲s码免费| 亚洲人成影院在线观看| 999任你躁在线精品免费不卡| 亚洲久热无码av中文字幕| 精品久久久久久亚洲|