* this program TODO
* @version
* @ausor widjan wu
*/
package file;
import java
import java
import java
import ncurrent
public class ChangeFileName
{
public static void main(String[] args)
{
Scanner in = new Scanner(System
System
String directory = in
System
String keywords = in
ExecutorService pool = Executors
ChangeName change = new ChangeName(new File(directory)
Future<Integer> result = pool
try {
System
} catch (ExecutionException e) {
e
} catch (InterruptedException e) {
}
pool
int largestPoolSize = ((ThreadPoolExecutor) pool)
System
}
}
class ChangeName implements Callable<Integer>
{
public ChangeName(File directory
this
this
this
}
public Integer call()
{
count =
try
{
File[] files = directory
ArrayList<Future<Integer》 results = new ArrayList<Future<Integer》()
for (File file : files) {
if (file
ChangeName change = new ChangeName(file
Future<Integer> result = pool
} else {
count++;
String path = file
int index
path = path
System
String oldName = file
String fileType = oldName
String newFName = path + keywords + count + fileType;
file
}
}
for(Future<Integer> result:results)
{
try
{
count +=result
}catch(ExecutionException e)
{
e
}
}
}catch(InterruptedException e)
{
}
return count;
}
private File directory;
private String keywords;
private ExecutorService pool;
private int count;
}
From:http://tw.wingwit.com/Article/program/Java/gj/201311/27511.html