锘??xml version="1.0" encoding="utf-8" standalone="yes"?>中文字幕亚洲区,国产天堂在线,狠狠久久综合http://www.aygfsteel.com/jiangwei/weizi2012zh-cnMon, 04 Aug 2025 20:39:19 GMTMon, 04 Aug 2025 20:39:19 GMT60java 鏂囦歡涓嬭澆http://www.aygfsteel.com/jiangwei/archive/2012/09/27/java.htmljiangweijiangweiThu, 27 Sep 2012 02:57:00 GMThttp://www.aygfsteel.com/jiangwei/archive/2012/09/27/java.htmlhttp://www.aygfsteel.com/jiangwei/comments/388668.htmlhttp://www.aygfsteel.com/jiangwei/archive/2012/09/27/java.html#Feedback2http://www.aygfsteel.com/jiangwei/comments/commentRss/388668.htmlhttp://www.aygfsteel.com/jiangwei/services/trackbacks/388668.html/**
  * 鏈湴涓嬭澆
  *
  * @param response
  * @throws FileNotFoundException
  */
 public void downloadLocal(HttpServletResponse response)
   throws FileNotFoundException {
  // 涓嬭澆鏈湴鏂囦歡
  String fileName = "Operator.doc".toString(); // 鏂囦歡鐨勯粯璁や繚瀛樺悕
  // 璇誨埌嫻佷腑
  InputStream inStream = new FileInputStream("c:/Operator.doc");// 鏂囦歡鐨勫瓨鏀捐礬寰?br />  // 璁劇疆杈撳嚭鐨勬牸寮?br />  response.reset();
  response.setContentType("bin");
  response.addHeader("Content-Disposition", "attachment; filename=\""
    + fileName + "\"");
  // 寰幆鍙栧嚭嫻佷腑鐨勬暟鎹?br />  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();
  }
 }

 /**
  * 緗戠粶鏂囦歡涓嬭澆
  *
  * @param response
  * @throws MalformedURLException
  */
 public void downloadNet(HttpServletResponse response)
   throws MalformedURLException {
  // 涓嬭澆緗戠粶鏂囦歡
  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);
   // 鏂囦歡鍚嶅簲璇ョ紪鐮佹垚UTF-8
  } else { // 綰笅杞芥柟寮?br />   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();
 }



jiangwei 2012-09-27 10:57 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 福建省| 三台县| 哈密市| 平定县| 鸡泽县| 兴宁市| 和静县| 永康市| 赣州市| 康定县| 永福县| 南郑县| 陆良县| 临高县| 茂名市| 岑溪市| 雅安市| 新余市| 凌海市| 屏东市| 长治县| 丽江市| 罗定市| 霸州市| 重庆市| 明光市| 巩留县| 沁阳市| 玛沁县| 谢通门县| 山东省| 陆良县| 徐水县| 临桂县| 麦盖提县| 崇明县| 甘南县| 徐汇区| 丹阳市| 胶南市| 惠安县|