posts - 24,  comments - 25,  trackbacks - 0

           

              /**
               * 字符型后面加空格
               * 
               * 
          @param str
               * 
          @param leng
               * 
          @return
               
          */

              
          public static String changString(String str, float leng)
              
          {
               
          if(StringUtil.isBlank(str))
               
          {
                str
          =" ";
               }

                  
          int count = new Double(leng).intValue();
                  
          for (int i = str.length(); i < count; i++)
                  
          {
                      str 
          = str + " ";
                  }

                  
          if (str.length() > count)
                  
          {
                      str 
          = str.substring(0, count);
                  }


                  
          return str;
              }


              
          /**
               * 數字型前面加零
               * 
               * 
          @param str
               * 
          @param leng
               * 
          @return
               
          */

              
          public static String changNumber(String str, float leng)
              
          {
               
          if(StringUtil.isBlank(str))
               
          {
                str
          ="0";
               }

                  
          int count = new Double(leng).intValue();
                  
          for (int i = str.length(); i < count; i++)
                  
          {
                      str 
          = "0" + str;
                  }

                  
          if (str.length() > count)
                  
          {
                      str 
          = str.substring(str.length() - count, str.length());
                  }


                  
          return str;
              }


              
          /**
               * 數字型前面加零
               * 
               * 
          @param num
               * 
          @param leng
               * 
          @return
               
          */

              
          public static String changInt(int num, float leng)
              
          {
                  String str 
          = num + "";
                  
          return changNumber(str, leng);
              }


              
          /**
               * 寫文件
               * 
               * 
          @param path
               * 
          @param content
               * 
          @return
               
          */

              
          public static boolean write(String path, String content)
              
          {
                  
          try
                  
          {
                      File file 
          = new File(path);
                      
          // 存在刪除
                      if (file.exists())
                      
          {
                          file.delete();
                      }

                      
          // 不存在新建
                      if (!file.createNewFile())
                      
          {
                          
          return false;
                      }

                      BufferedWriter output 
          = new BufferedWriter(new FileWriter(file));
                      output.write(content);
                      output.close();
                  }

                  
          catch (Exception e)
                  
          {
                      
          return false;
                  }

                  
          return true;
              }


              
          /**
               * 刪除文件
               * 
               * 
          @param path
               
          */

              
          public static void delete(String path)
              
          {
                  
          for (int i = 0; i < path.length; i++)
                  
          {
                      File file 
          = new File(path[i]);
                      
          if (file.exists())
                      
          {
                          file.delete();
                      }

                  }

              }

              
              
          /**
               * 昨天同一時間
               * 
          @param today
               * 
          @return
               
          */

              
          public static Date yesterday(Date today)
              
          {
                  Calendar cal 
          = Calendar.getInstance();
                  cal.setTime(today);
                  cal.add(Calendar.DATE, 
          -1);
                  
                  
          return cal.getTime();
              }

          posted on 2011-04-19 11:04 Jarry 閱讀(218) 評論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 类乌齐县| 台中县| 永福县| 新平| 宜兰市| 西乌| 滕州市| 闻喜县| 灵宝市| 红桥区| 张家港市| 剑川县| 本溪| 东丽区| 彩票| 唐海县| 平泉县| 香港| 盐池县| 旬邑县| 水富县| 蒲江县| 太仓市| 宁蒗| 梁平县| 彰武县| 马龙县| 兴宁市| 九台市| 易门县| 石家庄市| 临西县| 剑阁县| 江城| 天门市| 邢台县| 黄浦区| 鹤壁市| 湘乡市| 江永县| 曲松县|