67beeb2a320842db01253361c1e07f7823fe5ff4.svn-base 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package com.sinosoft.cm.util;
  2. import java.io.BufferedReader;
  3. import java.io.FileInputStream;
  4. import java.io.InputStreamReader;
  5. import java.util.regex.Matcher;
  6. import java.util.regex.Pattern;
  7. import org.jfree.util.Log;
  8. public class FileUtils {
  9. public static String getClassName(String path,String regex,String joinStr){
  10. StringBuffer joinSB=new StringBuffer(joinStr);
  11. Matcher mather=null;
  12. Pattern pt=Pattern.compile(regex);
  13. StringBuffer sb=new StringBuffer();
  14. try {
  15. FileInputStream fis=new FileInputStream(path);
  16. InputStreamReader isr=new InputStreamReader(fis,"utf-8");
  17. BufferedReader br=new BufferedReader(isr);
  18. String str=null;
  19. while((str=br.readLine())!=null){
  20. sb.append(new StringBuffer(str));
  21. }
  22. br.close();
  23. isr.close();
  24. fis.close();
  25. } catch (Exception e) {
  26. Log.info(e.getMessage());
  27. }
  28. mather=pt.matcher(sb.toString());
  29. sb=new StringBuffer();
  30. while(mather.find()){
  31. String tem=mather.group().trim();
  32. if(!"".equals(tem)){
  33. sb.append(tem).append(joinSB);
  34. }
  35. }
  36. return sb.toString();
  37. }
  38. }