posts - 325,  comments - 25,  trackbacks - 0

          import java.io.File;
          import java.io.FileNotFoundException;
          import java.io.FileOutputStream;
          import java.io.IOException;
          import java.io.InputStream;
          import java.io.OutputStream;

          import javax.servlet.http.HttpServletRequest;

          import org.apache.struts.upload.FormFile;

          public class UploadFile {
           private static String filePath = "/upload";

           @SuppressWarnings("deprecation")
           public static String buildDivContextFile(HttpServletRequest request,
             FormFile file, String id) throws FileNotFoundException, IOException {
            String fileName = "";
            filePath = request.getRealPath("/upload");
            synchronized (UploadFile.class) {
             File dirFile = new File(filePath);
             if (!dirFile.exists() || !dirFile.isDirectory()) {
              dirFile.mkdir();
             }
             int theIndex = 0;
             String fname = new String(file.getFileName().getBytes(), "utf-8");
             theIndex = fname.indexOf(".");
             String suffix = fname.substring(theIndex);
             fileName = id + suffix;
             InputStream streamIn = file.getInputStream();
             OutputStream streamOut = new FileOutputStream(filePath + "/"
               + fileName);
             int bytesRead = 0;
             byte[] buffer = new byte[8192];
             while ((bytesRead = streamIn.read(buffer, 0, 8192)) != -1) {
              streamOut.write(buffer, 0, bytesRead);
             }
             streamOut.close();
             streamIn.close();
             file.destroy();
            }
            return fileName;
           }
          }

          posted on 2008-12-15 17:05 長春語林科技 閱讀(145) 評論(0)  編輯  收藏 所屬分類: struts
          <2008年12月>
          30123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

           

          長春語林科技歡迎您!

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊

          收藏夾

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 陇南市| 鄢陵县| 榆林市| 清丰县| 毕节市| 朔州市| 如东县| 遵义市| 合阳县| 皋兰县| 屯留县| 黑龙江省| 陕西省| 固原市| 新竹市| 海原县| 昭觉县| 中方县| 安化县| 大城县| 古浪县| 建水县| 孟津县| 西城区| 湖北省| 哈巴河县| 盐池县| 社旗县| 乐亭县| 南川市| 曲周县| 崇仁县| 邢台市| 沂源县| 江达县| 庆阳市| 松桃| 兴隆县| 东兰县| 夏河县| 尼勒克县|