首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

关于资料上传

2013-07-16 
关于文件上传public static void upload(String strPath, ServletConfig config,HttpServletRequest reque

关于文件上传

public static void upload(String strPath, ServletConfig config,HttpServletRequest request, HttpServletResponse response) {File dir = new File(strPath);String w = JdjWsxydUpload.getFilesRecursive(dir);if (w.equals("ligang")) {} else {strPath += "/" + w;File fileDir = new File(strPath);if (fileDir.exists()) {System.out.println("删除文件信息成功!!!");fileDir.delete();}}SmartUpload su = new SmartUpload();try {su.initialize(config, request, response);su.upload();for (int i = 0; i < su.getFiles().getCount(); i++) {com.jspsmart.upload.File file = su.getFiles().getFile(i);// 若文件不存在则继续if (file.isMissing())continue;// 将文件另存file.saveAs("/webgroup/jdj/wsxyd/"+ JdjWsxydUpload.getOneName() + "."+ file.getFileExt());}} catch (SmartUploadException e) {e.printStackTrace();} catch (Exception e) {e.printStackTrace();}}private static String getOneName() {String name = "";name = "wsxyd" + System.currentTimeMillis();return name;}public static String getFilesRecursive(File dir) {if (dir.isDirectory()) {String sub[] = dir.list();if (sub.length > 0) {return sub[0];} else {return "ligang";}} else {return "ligang";}}public static void main(String[] args){File dir = new File("C:/windows/Help");String w = JdjWsxydUpload.getFilesRecursive(dir);System.out.println(w);}



Help文件夹下有Corporate等文件夹,所以dir.list()返回的是Help文件夹下的文件夹名字的列表

热点排行