锘??xml version="1.0" encoding="utf-8" standalone="yes"?>欧美少妇一区,一本一道综合狠狠老,婷婷综合在线http://www.aygfsteel.com/jiangwei/weizi2012zh-cnThu, 19 Jun 2025 10:12:41 GMTThu, 19 Jun 2025 10:12:41 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 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 吉林市| 南投市| 耒阳市| 昌吉市| 宜君县| 海城市| 河北区| 抚州市| 丹寨县| 霍城县| 尚义县| 滨海县| 隆昌县| 遵义县| 红原县| 开封市| 郓城县| 谢通门县| 大化| 库尔勒市| 五家渠市| 南岸区| 湘乡市| 临汾市| 竹北市| 全椒县| 陕西省| 永城市| 缙云县| 云浮市| 象山县| 嘉黎县| 绥化市| 招远市| 呼和浩特市| 正定县| 惠东县| 鹿泉市| 太仆寺旗| 金平| 鄂托克前旗|