<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 70,comments - 408,trackbacks - 0

    package com.util;

    import java.io.BufferedInputStream;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.FileWriter;
    import java.io.FilterInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.io.PrintWriter;
    import java.net.URL;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.Enumeration;
    import java.util.HashMap;
    import java.util.Map;
    import java.util.Properties;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;

    public class SuperUitl {
     
     public static void main(String[] args) {
      System.out.println();
     }
     
     /**
      * 全角轉(zhuǎn)半角
      * trr 要轉(zhuǎn)換成半角的字符串
      */
     public static String change(String str) {
      String outStr="";
      String test="";
      byte[] code = null;
      
      for(int i=0;i<str.length();i++) {    
       try {
        test = str.substring(i,i+1);
        code = test.getBytes("unicode");
       } catch(java.io.UnsupportedEncodingException e) {
       }    
       if (code[3] == -1) {
        code[2] = (byte)(code[2]+32);
        code[3] = 0;     

        try {      
         outStr = outStr + new String(code,"unicode");
        } catch(java.io.UnsupportedEncodingException e) {
        }     
       } else {
        outStr = outStr + test;
       }
      }
      return outStr;
     }
     
     /**
      * 根據(jù)key讀取value
      * filePath 要操作的properties文件路徑
      * key 要獲得數(shù)據(jù)的key
      */
     public static String readValue(String filePath,String key) {
      Properties props = new Properties();
            try {
             InputStream in = new BufferedInputStream (new FileInputStream(filePath));
             props.load(in);
             String value = props.getProperty (key);
                return value;
            } catch (Exception e) {
             return null;
            }
     }
     
     /**
      * 讀取properties的全部信息
      * filePath 要操作的properties文件路徑
      */
        public static Map readProperties(String filePath) {
         Map map = new HashMap();
         Properties props = new Properties();
            try {
             InputStream in = new BufferedInputStream (new FileInputStream(filePath));
             props.load(in);
                Enumeration en = props.propertyNames();
                 while (en.hasMoreElements()) {
                  String key = (String) en.nextElement();
                        String Property = props.getProperty (key);
                        map.put(key,Property);
                    }
                 return map;
            } catch (Exception e) {
             return null;
            }
        }

        /**
      * 寫入properties信息
      * filePath 要操作的properties文件路徑
      * key 要寫入的key
      * value 要寫入的value
      */
        public static boolean writeProperties(String filePath,String key,String value) {
         Properties prop = new Properties();
         try {
          InputStream fis = new FileInputStream(filePath);
                //從輸入流中讀取屬性列表(鍵和元素對(duì))
                prop.load(fis);
                //調(diào)用 Hashtable 的方法 put。使用 getProperty 方法提供并行性。
                //強(qiáng)制要求為屬性的鍵和值使用字符串。返回值是 Hashtable 調(diào)用 put 的結(jié)果。
                OutputStream fos = new FileOutputStream(filePath);
                prop.setProperty(key,value);
                //以適合使用 load 方法加載到 Properties 表中的格式,
                //將此 Properties 表中的屬性列表(鍵和元素對(duì))寫入輸出流
                prop.store(fos, "Update '" + key + "' value");
                return true;
            } catch (IOException e) {
             return false;
            }
        }
       
        /**
      * 返回標(biāo)準(zhǔn)系統(tǒng)時(shí)間
      */
        public static String getDate() {
      SimpleDateFormat ft=null;
      Date date=null;
      Calendar cl= Calendar.getInstance();
      cl.setTime(new java.util.Date());
      date=cl.getTime();
      ft=new SimpleDateFormat("yyyy-MM-dd HH:mm");
      String dateTime = ft.format(date);
      return dateTime;
     }
       
        /**
      * 從指定的字符串中提取Email
      * content 指定的字符串
      */
     public static String parse(String content) {
      String email = null;
      if (content==null || content.length()<1) {
       return email;
      }
      //找出含有@
      int beginPos;
      int i;
      String token = "@";
      String preHalf="";
      String sufHalf = "";
      
      beginPos = content.indexOf(token);
      if (beginPos>-1) {
       //前項(xiàng)掃描
       String s = null;
       i= beginPos;
       while(i>0) {
        s = content.substring(i-1,i);
        if (isLetter(s))
         preHalf = s+preHalf;
        else
         break;
        i--;
       }
       //后項(xiàng)掃描
       i= beginPos+1;
       while( i<content.length()) {
        s = content.substring(i,i+1);
        if (isLetter(s))
         sufHalf =  sufHalf +s;
        else
         break;
        i++;  
       }
       //判斷合法性
       email = preHalf + "@" + sufHalf;
       if (isEmail(email)) {
        return email;
       }
      }
      return null;
     }
     
     /**
      * 判斷是不是合法Email
      * email Email地址
      */
     public static boolean isEmail(String email) {
      try {
       if (email==null || email.length()<1 || email.length()>256) {
        return false;
       }
       
       String check = "^([0-9a-zA-Z]+[_.0-9a-zA-Z-]+)@([a-zA-Z0-9-]+[.])+([a-zA-Z]{2,3})$";
       Pattern regex = Pattern.compile(check);
       Matcher matcher = regex.matcher(email);
       boolean isMatched = matcher.matches();
       if(isMatched) {
        return true;
       } else {
        return false;
       }
      } catch (RuntimeException e) {
       return false;
      }
     }
     
     /**
      * 判斷是不是合法字符
      * c 要判斷的字符
      */
     public static boolean isLetter(String c) {
      boolean result = false;
      
      if (c==null || c.length()<0) {
       return false;
      }
      //a-z 
      if (c.compareToIgnoreCase("a")>=0 && c.compareToIgnoreCase("z")<=0) {
       return true;
      }
      //0-9
      if (c.compareToIgnoreCase("0")>=0 && c.compareToIgnoreCase("9")<=0) {
       return true;
      }
      //. - _
      if (c.equals(".") || c.equals("-") || c.equals("_") ) {
       return true;
      }
      return result; 
     }
     
     /**
      * 刪除整個(gè)目錄的全部圖片
      * filePath 要?jiǎng)h除的目錄路徑
      */
     public static boolean deleteImage(String filePath) {
      try {
       File file = new File(filePath);
       File[] files = file.listFiles();
       for(int i=0;i<files.length;i++) {
        try {
         //系統(tǒng)文件不刪除
         if(!(files[i].getName()).equalsIgnoreCase("Thumbs.db")) {
          if(files[i].isFile()) {
           files[i].delete();
          } else if(files[i].isDirectory()) {
           files[i].delete();
          } else {
           files[i].delete();
          }
         }
        } catch (RuntimeException e) {;
        }
       }
       return true;
      } catch (RuntimeException e) {
       return false;
      }
     }
     
     /**
      * 保存網(wǎng)絡(luò)上的圖片到指定目錄
      * filePath 要保存到本地服務(wù)器的目錄
      * imagePath 網(wǎng)絡(luò)圖片的UIL地址
      */
     public static boolean saveImage(String filePath,String imagePath) {
      try {
       if(imagePath.length()>1024 || imagePath.equals("")) {
        return false;
       }
       String fileName = imagePath.substring(imagePath.lastIndexOf("/")+1,imagePath.length());
       filePath = filePath+fileName;
       URL url = null;
       try {
         url = new URL(imagePath);
       } catch(Exception e) {
         return false;
       }
       FilterInputStream in=(FilterInputStream) url.openStream();
       File fileOut=new File(filePath);
       FileOutputStream out=new FileOutputStream(fileOut);
       byte[] bytes=new byte[1024];
       int c;
       while((c=in.read(bytes))!=-1) {
        out.write(bytes,0,c);
       }
       in.close();
       out.close();
       return true;
      } catch(Exception e) {
       return false;
      }
     }
     
     /**
      * 寫入日志
      * filePath 日志文件的路徑
      * code 要寫入日志文件的內(nèi)容
      */
     public static boolean print(String filePath,String code) {
      try {
       File tofile=new File(filePath);
       FileWriter fw=new FileWriter(tofile,true);
       BufferedWriter bw=new BufferedWriter(fw);
       PrintWriter pw=new PrintWriter(bw);
       
       System.out.println(getDate()+":"+code);
       pw.println(getDate()+":"+code);
       pw.close();
       bw.close();
       fw.close();
       return true;
      } catch (IOException e) {
       return false;
      }
     }
     
     /**
      * 判斷是不是合法手機(jī)
      * handset 手機(jī)號(hào)碼
      */
     public static boolean isHandset(String handset) {
      try {
       if(!handset.substring(0,1).equals("1")) {
        return false;
       }
       if (handset==null || handset.length()!=11) {
        return false;
       }
       String check = "^[0123456789]+$";
       Pattern regex = Pattern.compile(check);
       Matcher matcher = regex.matcher(handset);
       boolean isMatched = matcher.matches();
       if(isMatched) {
        return true;
       } else {
        return false;
       }
      } catch (RuntimeException e) {
       return false;
      }
     }
    }

    posted on 2007-04-28 13:38 我心依舊 閱讀(1797) 評(píng)論(1)  編輯  收藏

    FeedBack:
    # re: 工作之余,整理了一下平時(shí)處理數(shù)據(jù)的一些常用的,簡(jiǎn)單的方法。希望對(duì)學(xué)習(xí)JAVA的朋友有點(diǎn)幫助。[未登錄]
    2007-07-05 03:15 | sam
    Nice, thanks
      回復(fù)  更多評(píng)論
      

    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 暖暖在线视频免费视频| 日韩免费高清一级毛片| 69影院毛片免费观看视频在线| 亚洲综合区小说区激情区| 免费无码婬片aaa直播表情| 免费看国产曰批40分钟| 美女18毛片免费视频| mm1313亚洲精品无码又大又粗| 曰批免费视频播放免费| 亚洲午夜成人精品电影在线观看| 四虎影视久久久免费| 亚洲啪啪AV无码片| 国产精品区免费视频| 亚洲国产视频一区| 美女黄网站人色视频免费国产| 狠狠综合亚洲综合亚洲色| 亚洲人成人无码网www国产| 国产精品永久免费视频| 亚洲av无码乱码国产精品fc2| 无码人妻丰满熟妇区免费| 亚洲国产超清无码专区| 国产成人无码区免费A∨视频网站| 色噜噜的亚洲男人的天堂| 亚洲色偷拍另类无码专区| h在线观看视频免费网站| 亚洲国产综合AV在线观看| 亚洲av无码天堂一区二区三区 | 999zyz**站免费毛片| 亚洲无线电影官网| 国内自产少妇自拍区免费| 久久成人18免费网站| 亚洲AV无码国产精品色| 国产一级做a爱免费视频| 热久久这里是精品6免费观看| 亚洲国产韩国一区二区| 亚洲AV无码之日韩精品| 3344免费播放观看视频| 五月天婷婷免费视频| 亚洲乱码中文字幕小综合| 伊在人亚洲香蕉精品区麻豆| 日本免费在线观看|