技术架构:Struts2(json-plugin) + Spring2 + ExtJS2.2 无数据库。
原创作者:
yourgame已经实现的功能:
1.多文件队列批量上传,友好的上传进度条,完整的上传进度信息.
2.实现了文件在线压缩解压功能(可以压缩成zip格式,可以直接解压缩RAR文件格式)
3.实现了新建文件夹,以及删除文件和文件夹.
存在的问题:删除文件有时候会异常.
注意,tomcat(server.xml)最好能设置一下URIEncoding
Xml代码
- 1. <Connector port="8080" maxHttpHeaderSize="8192"
- 2. maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
- 3. enableLookups="false" redirectPort="8443" acceptCount="100"
- 4. connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="UTF-8"/>
- <Connector port="8080" maxHttpHeaderSize="8192"
- maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
- enableLookups="false" redirectPort="8443" acceptCount="100"
- connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="UTF-8"/>
复制代码删除文件的地方小改了一下,原先引起的错误是文件资源在内存中还未释放掉,就试行把文件删除,虽说有file=null,但这样的删除结果是有时候行有时候就不行,GC没及时调那资源就不会释放掉的。
Java 代码
- 1. /**
- 2. * 多文件删除
- 3. *
- 4. * @return
- 5. */
- 6. public String deleteFiles() {
- 7. String rootPath = getSession().getServletContext().getRealPath("/");
- 8. rootPath += ROOT;
- 9. // File file = new File(rootPath);
- 10. //为什么此处要判断不存在就创建??
- 11. // if(!file.exists()){
- 12. // file.mkdirs();
- 13. // }
- 14. // file = null;
- 15. boolean flag = false;
- 16. try {
- 17. for (String path : paths) {
- 18. // file = new File(rootPath + path);
- 19. flag = MyUtils.delFiles(rootPath + path);
- 20. if (!flag) {
- 21. break;
- 22. }
- 23. }
- 24. } catch (RuntimeException e) {
- 25. flag = false;
- 26. e.printStackTrace();
- 27. }
- 28. // finally {
- 29. // file = null;
- 30. // }
- 31. setSuccess(flag);
- 32. return SUCCESS;
- 33. }
- /**
- * 多文件删除
- *
- * @return
- */
- public String deleteFiles() {
- String rootPath = getSession().getServletContext().getRealPath("/");
- rootPath += ROOT;
- // File file = new File(rootPath);
- //为什么此处要判断不存在就创建??
- // if(!file.exists()){
- // file.mkdirs();
- // }
- // file = null;
- boolean flag = false;
- try {
- for (String path : paths) {
- // file = new File(rootPath + path);
- flag = MyUtils.delFiles(rootPath + path);
- if (!flag) {
- break;
- }
- }
- } catch (RuntimeException e) {
- flag = false;
- e.printStackTrace();
- }
- // finally {
- // file = null;
- // }
- setSuccess(flag);
- return SUCCESS;
- }
复制代码改下回调的方法
Java 代码
- 1. /**
- 2. * 删除指定文件路径下面的所有文件和文件夹
- 3. *
- 4. * @param file
- 5. */
- 6. public static boolean delFiles(String fileName) {
- 7. boolean flag = false;
- 8. try {
- 9. File file = new File(fileName);
- 10. if (file.exists()) {
- 11. if (file.isDirectory()) {
- 12. String[] contents = file.list();
- 13. for (int i = 0; i < contents.length; i++) {
- 14. delFiles(file.getAbsolutePath() + "/" + contents);
- 15. // File file2X = new File(file.getAbsolutePath() + "/" + contents);
- 16. // if (file2X.exists()) {
- 17. // if (file2X.isFile()) {
- 18. // flag = file2X.delete();
- 19. // } else if (file2X.isDirectory()) {
- 20. // delFiles(file2X);
- 21. // }
- 22. // } else {
- 23. // throw new RuntimeException("File not exist!");
- 24. // }
- 25. }
- 26. }
- 27. flag = file.delete();
- 28. } else {
- 29. throw new RuntimeException("File not exist!");
- 30. }
- 31. } catch (Exception e) {
- 32. flag = false;
- 33. e.printStackTrace();
- 34. }
- 35. return flag;
- 36. }
复制代码 系统截图:
附件:
2010-03-19_121751.gif 附件:
2010-03-19_121859.gif 附件:
2010-03-19_121914.gif 附件:
2010-03-19_121932.gif