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 長春語林科技 閱讀(142) 評論(0)  編輯  收藏 所屬分類: struts
          <2008年12月>
          30123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

           

          長春語林科技歡迎您!

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊

          收藏夾

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 唐河县| 昌都县| 江都市| 望江县| 庆阳市| 通榆县| 托克托县| 邵东县| 建始县| 永丰县| 吉安市| 芮城县| 昌都县| 桂东县| 扬州市| 洛隆县| 邵武市| 沧源| 惠州市| 新巴尔虎左旗| 岳普湖县| 桑日县| 乌兰浩特市| 陇西县| 巴彦淖尔市| 育儿| 祁东县| 永登县| 尉犁县| 安吉县| 东兰县| 青铜峡市| 扬州市| 连城县| 绥阳县| 六枝特区| 大同市| 施秉县| 柳江县| 福建省| 报价|