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

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

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

    用動作去驅動未來

    生命在于運動,讓自己身體的每一個細胞都動起來吧.

     

    2012年11月9日

    List分拆為多少個List對象

    用遞歸實現了這么一個需求,一個list對象中存儲了大量的數據,所以打算分拆為多個小的list,然后用多線程處理這些list,實現業務需求。直接上代碼:

    import java.util.HashMap;
    import java.util.LinkedList;
    import java.util.List;
    import java.util.Map;

    public class TestClass {
        private Map<String,ArrayList<String>> map = new HashMap<String,ArrayList<String>>();
        private int k = 0;

        public
     Map<String,ArrayList<String>> newTableList(ArrayList<String> list,int num) {
            List
    <String> tempList = new ArrayList<String>();
            
    int size = list.size();
            System.out.println(
    "========================================");
            List
    <String> newList = (List<String>) list.clone();
            
    for (int i = 0; i < size; i++) {
                
    if(i < num) {
                    String str 
    = list.get(i);
                    tempList.add(str);
                } 
    else {
                    
    break;
                }
            }
            
            
    if (list!=null && size!=0) {
                k
    ++;
                map.put(String.valueOf(k), (ArrayList
    <String>) tempList);
                System.out.println(
    "Key:"+k+",list size:"+tempList.size());
                System.out.println(
    "========================================");
                
    for (int i = 0; i < tempList.size(); i++) {
                    String tempStr 
    = tempList.get(i);
                    
    boolean isContains = newList.contains(tempStr);
                    
    if(isContains) {
                        newList.remove(tempStr);
                    }
                }
                newTableList((ArrayList
    <String>)newList,num);
            }
            
            
    return map;
        }

    public static void main(String[] args) throws SQLException {
            TestClass ed = new TestClass();
            ArrayList<String> tempList = new ArrayList<String>();
            tempList.add("111");
            tempList.add("222");
            tempList.add("333");
            tempList.add("444");
            tempList.add("555");
            tempList.add("666");
            tempList.add("777");
            tempList.add("888");
            tempList.add("999");
            tempList.add("100");
            tempList.add("aaa");
            tempList.add("bbb");
            tempList.add("ccc");
            tempList.add("ddd");
            
            ed.newTableList(tempList,5);
        }
    }

    希望這段代碼能幫助到些人。

    posted @ 2013-01-30 17:40 黑螞蟻 閱讀(1993) | 評論 (0)編輯 收藏

    java對指定目錄下文件的讀寫

    最近因為項目的國際化的需要,需要對整個項目的100來個插件做國際化,這是一件痛苦的事情,因為純體力勞動。為了省點工作量,想著能不能寫個程序批處理了,減少點工作量,于是就有了下面的代碼。

    1.讀取指定的(.java)文件:
    public static String readFile(String path) throws IOException {
            File f = new File(path);
            StringBuffer res = new StringBuffer();
            String filePathStr = f.getPath();
            System.out.println("獲取文件的路徑:::::::"+filePathStr);
            
            FileInputStream fis = new FileInputStream(f);
            InputStreamReader isr = new InputStreamReader(fis,Charset.forName("GBK")); //以gbk編碼打開文本文件
            BufferedReader br = new BufferedReader(isr, 8192 * 8);
            
            String line = null;
            int linenum = 0;
            while((line=br.readLine())!=null) {
                linenum ++;
                res.append(line+"此處可以添加你自己的字符串處理邏輯"+"\r\n");
            }
            br.close();
            
            return res.toString();
        }
    2.讀取的文件內容信息寫到指定的(.java)文件
    public static boolean writeFile(String cont, String path) {
            try {
                File dist = new File(path);
                OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(dist),"GBK"); 
                writer.write(cont);
                writer.flush();
                writer.close();
                return true;
            } catch (IOException e) {
                e.printStackTrace();
                return false;
            }
        }
    3.查找指定目錄下所有符合條件的.java文件,并更新文件信息
        /**
         * 查找文件
         * @param f
         * @throws IOException
         */
        public static void findFile(File f) throws IOException {
            if(f.exists()) {
                if(f.isDirectory()) {
                    for(File fs:f.listFiles(ff)) {
                        findFile(fs);
                    }
                } else {
                        updateFile(f);
                }
            }
        }
        
        /**
         * 逐行讀java文件
         * @param f
         * @throws IOException
         */
        private static void updateFile(File f) throws IOException {
            String filePathStr = f.getPath();
            System.out.println("開始讀取文件的路徑:::::::"+filePathStr);
            FileInputStream fis = new FileInputStream(f);
            InputStreamReader isr = new InputStreamReader(fis,Charset.forName("GBK")); //以gbk編碼打開文本文件
            BufferedReader br = new BufferedReader(isr, 8192 * 8);
            
            String line = null;
            int linenum = 0;
            StringBuffer res = new StringBuffer();
            while((line=br.readLine())!=null) {
                String updateStr= updateStr(line);
                res.append(updateStr+"\r\n");
                
                if(!line.trim().equals(updateStr.trim())) {
                    linenum ++;
                }
            }
            br.close();
            
            //如果文件有修改,則修改后的文件,覆蓋原有文件
            if(linenum>0) {
                System.out.println("=============================");
                System.out.println("filePathStr:"+filePathStr);
                System.out.println("文件修改了:"+linenum+"處。");
                System.out.println("=============================");
                String cont = res.toString();
                ReadWriteFile.write(cont, filePathStr);
            }
        }
        
        /**
         * 驗證讀取的字符串信息
         * 和更新字符串信息
         * @param str
         */
        private static String updateStr(String str) {
            //判斷字符串是否是需要更新的字符串
            boolean isok = filterStr(str);
            int strNum = StringValidation.strNum(str, StringValidation.ch);
            if(isok || strNum == 0) {
                return str;
            } else {
                String temp = ""; 
                for(int i=1;i<=strNum/2;i++) {
                    temp += " //$NON-NLS-"+i+"$"; //需要添加的字符
                }
                str = str+temp;
            }
            return str;
        }
        
        //過濾文件類型
        private static FileFilter ff = new FileFilter() {
            public boolean accept(File pathname) {
                String path = pathname.getName().toLowerCase();
                logger.info("FileFilter path::::"+path);
                //只匹配 .java 結尾的文件
                if (pathname.isDirectory() || path.endsWith(".java")) {
                    return true;
                }
                return false;
            }
        };

        /**
         * 過濾掉不需要處理的字符串
         * @param str
         * @return
         */
        public static boolean filterStr(String str) {
            boolean isok = false;
            
            //過濾字符串
            isok = (str.indexOf("import ")>=0)
                    || (str.indexOf("package ")>=0)
                    || (str.indexOf(" class ")>=0)
                    || (str.indexOf("http://$NON-NLS")>=0)
                    || (str.indexOf("http://")==0)
                    || (str.indexOf("/*")>=0)
                    || (str.indexOf("*")>=0)
                    || (str.trim().indexOf("@")==0)
                    || (str.indexOf("\"")==-1)
                    || ("".equals(str))
                    || isCh(str);
            return isok;
        }

        /**
         * 驗證字符串是否含有中文字符
         * @param str
         * @return
         */
        public static boolean isCh(String str) {
            Pattern   pa   =   Pattern.compile("[\u4E00-\u9FA0]");
            Matcher   m   =   pa.matcher(str);
            boolean isok = m.find();
            return isok;
        }

    總結:當我們拿到一個別人給的需求,先不要急于去處理,先分析,再分析,然后做出最優的解決方案,處理好這項工作。

    posted @ 2012-11-23 15:32 黑螞蟻| 編輯 收藏

    Eclipse下添加反編譯插件jad.exe

    相信學習java的都會用到反編譯工具查看.class文件,接下來簡單的記錄下,在eclipse下安裝反編譯插件的過程,希望能幫助到你。

    首先: 我們需要下載:net.sf.jadclipse_3.3.0.jar  參考下載地址:http://download.csdn.net/detail/lk_kuaile/1725313
    其次: 還需要下載:jad.exe 參考下載地址:http://ishare.iask.sina.com.cn/f/15267016.html?from=like

    接下來:我把下載的 net.sf.jadclipse_3.3.0.jar 放入到自己的文件夾下:eclipse\plugins 目錄下。
                重啟eclipse,打開window-preferences--java 指定jad.exe的絕對路徑。
               
    點擊ok,就可以了。我們就可以很方便的在Eclipse下查看jar下的.class 文件了。

    posted @ 2012-11-09 16:46 黑螞蟻 閱讀(2138) | 評論 (3)編輯 收藏

    導航

    統計

    公告

    路在腳下,此刻,出發。

    常用鏈接

    留言簿

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    相冊

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 鲁啊鲁在线视频免费播放| 亚洲高清乱码午夜电影网| 免费v片视频在线观看视频| 亚洲人成高清在线播放| 午夜不卡久久精品无码免费| 在线免费观看视频你懂的| 亚洲av高清在线观看一区二区 | 一个人看的www视频免费在线观看 一个人看的免费观看日本视频www | 18禁美女黄网站色大片免费观看| 四色在线精品免费观看| 亚洲第一男人天堂| 日本v片免费一区二区三区 | 中国一级特黄高清免费的大片中国一级黄色片 | 亚洲日本韩国在线| 亚洲啪啪免费视频| 久草视频免费在线观看| 亚洲不卡在线观看| 日本免费人成黄页在线观看视频 | 日韩亚洲人成在线综合日本| 无码av免费一区二区三区| 亚洲视频免费在线播放| 免费国产黄线在线观看| 疯狂做受xxxx高潮视频免费| 日韩精品免费一级视频| 亚洲午夜精品国产电影在线观看| 最近2019中文免费字幕| 亚洲男人的天堂在线| 97无码免费人妻超级碰碰夜夜 | 亚洲另类无码专区丝袜| 亚洲美日韩Av中文字幕无码久久久妻妇| 91亚洲国产在人线播放午夜 | jizz免费在线影视观看网站| 99久久国产热无码精品免费| 亚洲AV无码成人精品区日韩| 亚洲乱码国产一区三区| 一级毛片免费视频网站| 亚洲爱情岛论坛永久| 国产精品免费无遮挡无码永久视频| 亚洲国产精品综合久久网各| 99精品视频在线观看免费专区| 亚洲男人天堂2018av|