posts - 24,  comments - 25,  trackbacks - 0
          <2011年4月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          1234567

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          文章檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

           

              /**
               * 字符型后面加空格
               * 
               * 
          @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 閱讀(224) 評論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 类乌齐县| 普格县| 淮滨县| 克拉玛依市| 乌拉特前旗| 塔河县| 通州区| 卢氏县| 桃园市| 奉贤区| 安远县| 陇川县| 酒泉市| 和龙市| 通江县| 盐源县| 海口市| 麻江县| 天全县| 沁阳市| 绥芬河市| 新沂市| 秦皇岛市| 扎赉特旗| 宽城| 中西区| 宜君县| 安仁县| 滦平县| 六枝特区| 繁昌县| 班戈县| 鄂州市| 临汾市| 娄底市| 元谋县| 木兰县| 开封县| 比如县| 乌兰县| 建昌县|