細心!用心!耐心!

          吾非文人,乃市井一俗人也,讀百卷書,跨江河千里,故申城一游; 一兩滴辛酸,三四年學業,五六點粗墨,七八筆買賣,九十道人情。

          BlogJava 聯系 聚合 管理
            1 Posts :: 196 Stories :: 10 Comments :: 0 Trackbacks
          ?1 package ?com.stt.doss.common.util.upload;
          ?2
          ?3 import ?java.io.BufferedInputStream;
          ?4 import ?java.io.BufferedOutputStream;
          ?5 import ?java.io.File;
          ?6 import ?java.io.FileNotFoundException;
          ?7 import ?java.io.FileOutputStream;
          ?8 import ?java.io.IOException;
          ?9 import ?java.io.InputStream;
          10 import ?java.io.OutputStream;
          11
          12 import ?org.apache.commons.logging.Log;
          13 import ?org.apache.commons.logging.LogFactory;
          14 import ?org.apache.struts.upload.FormFile;
          15
          16 /**
          17 ?*?<p>
          18 ?*?Title:
          19 ?*?</p>
          20 ?*?<p>
          21 ?*?Description:
          22 ?*?</p>
          23 ?*?<p>
          24 ?*?Copyright:?Copyright?(c)?2006
          25 ?*?</p>
          26 ?*?<p>
          27 ?*?Company:?stt
          28 ?*?</p>
          29 ?*
          30 ?*? @author ?william
          31 ?*? @version ?1.0
          32 ? */

          33 public ? class ?UploadHelper? {
          34
          35 ???? private ? static ?Log?log? = ?LogFactory.getLog(UploadHelper. class );
          36
          37 ???? public ? static ? void ?uploadFileForm(FormFile?formFile,?String?folderPath,
          38 ????????????String?fileName)? {
          39 ????????log.info( " UploadHelper()?uploadFileForm?start. " );
          40 ???????? // ?retrieve?the?file?data
          41 ????????InputStream?inputStream? = ? null ;
          42 ????????OutputStream?outputStream? = ? null ;
          43
          44 ???????? int ?bytesRead? = ? 0 ;
          45 ???????? byte []?buffer? = ? new ? byte [ 8192 ];
          46
          47 ????????File?file? = ? new ?File(folderPath);
          48 ???????? if ?( ! file.exists())? {
          49 ???????????? boolean ?f? = ?file.mkdir();
          50 ???????????? if ?( ! f)? {
          51 ????????????????f? = ?file.mkdirs();
          52 ???????????????? if ?( ! f)? {
          53
          54 ????????????????}

          55 ????????????}

          56
          57 ????????}

          58
          59 ???????? try ? {
          60 ????????????StringBuffer?filePath? = ? new ?StringBuffer();
          61 ????????????filePath.append(folderPath);
          62 ????????????filePath.append(File.separator);
          63 ????????????filePath.append(fileName);
          64
          65 ????????????inputStream? = ? new ?BufferedInputStream(formFile.getInputStream(),
          66 ???????????????????? 2048 );
          67 ????????????outputStream? = ? new ?BufferedOutputStream( new ?FileOutputStream(
          68 ????????????????????filePath.toString()),? 2048 );
          69
          70 ???????????? // ?read?and?write
          71 ???????????? while ?((bytesRead? = ?inputStream.read(buffer,? 0 ,? 8192 ))? != ? - 1 )? {
          72 ????????????????outputStream.write(buffer,? 0 ,?bytesRead);
          73 ????????????}

          74 ????????}
          ? catch ?(FileNotFoundException?fnfe)? {
          75 ????????????fnfe.printStackTrace();
          76 ????????}
          ? catch ?(IOException?ioe)? {
          77 ????????????ioe.printStackTrace();
          78 ????????}
          ? finally ? {
          79 ???????????? try ? {
          80 ???????????????? // ?close?the?stream
          81 ????????????????outputStream.close();
          82 ????????????????inputStream.close();
          83 ????????????}
          ? catch ?(IOException?ioe)? {
          84 ????????????????ioe.printStackTrace();
          85 ????????????}

          86 ???????????? // ?destroy?the?temporary?file
          87 ????????????formFile.destroy();
          88 ????????}

          89
          90 ????}
          ? // ?end?uploadFileForm
          91
          92 ???? public ? static ? void ?deleteFile(String?path)? {
          93 ????????log.info( " UploadHelper()?deleteFile?start. " );
          94 ????????File?file? = ? new ?File(path);
          95 ????????file.delete();
          96 ????}

          97 }

          98
          posted on 2007-03-16 15:27 張金鵬 閱讀(229) 評論(0)  編輯  收藏 所屬分類: core java中的一些數據結構的處理
          主站蜘蛛池模板: 中江县| 五指山市| 垦利县| 洪雅县| 东丰县| 象山县| 汉源县| 曲靖市| 邓州市| 济阳县| 收藏| 汉寿县| 黑龙江省| 旬阳县| 峡江县| 墨脱县| 农安县| 巴南区| 鄂尔多斯市| 罗田县| 古浪县| 建水县| 奈曼旗| 太湖县| 博爱县| 蓬溪县| 大渡口区| 西乡县| 宕昌县| 牟定县| 扶风县| 六盘水市| 稻城县| 巫山县| 三门县| 西乌珠穆沁旗| 罗源县| 噶尔县| 孟州市| 民和| 西林县|