工具函数

清除指定目录

  1. /**
  2. *Recursivelydeleteswholecontentofthegivenfolder.
  3. *@paramfolderfoldertobeemptied
  4. *@return<code>true</code>ifgivenfolderbecomesemptyornotexists
  5. */
  6. publicstaticbooleanemptyFolder(finalFilefolder){
  7. if(!folder.isDirectory()){
  8. returntrue;
  9. }
  10. File[]files=folder.listFiles();
  11. booleanresult=true;
  12. for(Filefile:files)
  13. {
  14. if(file.isDirectory()){
  15. if(emptyFolder(file)){
  16. result&=file.delete();
  17. }else{
  18. result=false;
  19. }
  20. }else{
  21. result&=file.delete();
  22. }
  23. }
  24. returnresult;
  25. }

通过类名创建一个实例

  1. protectedObjectcreateClassInstance(finalStringclassName)
  2. throwsInstantiationException,IllegalAccessException,
  3. ClassNotFoundException{
  4. ClassLoadercl=Thread.currentThread().getContextClassLoader();
  5. if(cl!=null){
  6. try{
  7. returncl.loadClass(className).newInstance();
  8. }catch(ClassNotFoundExceptioncnfe){
  9. //ignore
  10. }
  11. }
  12. cl=getClass().getClassLoader();
  13. if(cl!=null){
  14. try{
  15. returncl.loadClass(className).newInstance();
  16. }catch(ClassNotFoundExceptioncnfe){
  17. //ignore
  18. }
  19. }
  20. returnClassLoader.getSystemClassLoader().loadClass(
  21. className).newInstance();
  22. }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值