0

私のタイムゾーンでおはよう.

次のコードがあります。

Iterator<File> files = FileUtils.iterateFiles(new File(directoryPath), new String[]{"java"}, true);

        for(String file : ws){
            while(files.hasNext()){
                current = files.next();
                if(!current.isDirectory()){
                    if(current.getName().matches(file+".*ServiceProxy.*")){
        //I need to start the cycle again from the beginning to search in each
    //file for the ServiceProxy string
    //Something like this
            // cloneFiles = files.clone();
         //while(cloneFiles.hasNext()){
              file = files.next();
              //search inside the file code
         }
                    }
                }
            }   
        }

このアクションは時間的に非常にコストがかかるため、Iterator を複製したい

FileUtils.iterateFiles(new File(directoryPath), new String[]{"java"}, true);

よろしくお願いします

4

2 に答える 2

0

使用できます

Collection<File> files = FileUtils.listFiles(new File(directoryPath), 
    new String[]{"java"}, true);

ファイルのコレクションを作成し、それを再利用してさらに繰り返します。この方法では、ファイルを反復処理するたびにルート フォルダーをスキャンしません。

于 2013-10-25T10:22:56.283 に答える